def __init__(self, **kwargs): fuels84 = [("CH4", 0.958), ("C2H4", 0.008), ("CO", 0.004), ("O2", 0.002), ("CO2", 0.006), ("N2", 0.022)] fuels79 = Composition(("C", 0.5921), ("H", 0.0377), ("S", 0.0211), ("O", 0.112), ("N", 0.0128)) fuels75 = Composition(("C", 0.7), ("H", 0.043), ("O", 0.075), ("N", 0.013)) fuel = kwargs.pop("fuel", fuels84) # fuel = fuels84 measured_co2 = kwargs.pop("measured_co2", 0) measured_o2 = kwargs.pop("measured_o2", 0) super().__init__(**kwargs) if fuel: try: fuel = Composition(*fuel) except ValueError: show_popup( "Error", 'Please ensure that the sum of proportions is 100%') try: self.osw_calculations = OstwaldCalculations( fuel, measured_co2, measured_o2) self.ostwald_triangle_graph = OstwaldTriangle( self.osw_calculations) self.ostwald_triangle_graph.draw(self.canvas) except (molmass.molmass.FormulaError, ZeroDivisionError) as e: if isinstance(e, molmass.molmass.FormulaError): show_popup( "Error", 'Please ensure that all chemicals are in' '\n capital letters and are chemically valid.') else: show_popup("Error", 'Please ensure that all proportions are numbers.')
def test_non_existing_element_returns0(self): args = [ CompositionNode(FormulaWrapper("C"), 0.7), CompositionNode(FormulaWrapper("H"), 0.043) ] fuel = Composition(*args) self.assertEqual(0, fuel["O"])
def test_init_args_as_list(self): args = [ CompositionNode(FormulaWrapper("C"), 0.7), CompositionNode(FormulaWrapper("H"), 0.043) ] fuel = Composition(*args) self.assertEqual(0.7, fuel["C"])
def test_complex_formula_in_init(self): args = [ CompositionNode(FormulaWrapper("C2H4"), 0.7), CompositionNode(FormulaWrapper("H"), 0.043) ] fuel = Composition(*args) with self.assertRaises(KeyError): c = fuel["C2H4"]
def test_vocoh2o_84(self): f = Composition(("CH4", 0.958), ("C2H4", 0.008), ("CO", 0.004), ("O2", 0.002), ("CO2", 0.006), ("N2", 0.022)) m = Mollier(f) self.assertAlmostEqual(1.451, m.Ocoh2o, delta=0.01) # the book says 8.843 but it should be 0.842
def test_is_gas_true_when_c3h8_present(self): fuel = Composition( ("S", 0.11), ("C3H8", 0.11) ) self.assertEqual(True, fuel.is_gas)
def test_init_args(self): fuel = Composition( CompositionNode(FormulaWrapper("C"), 0.7), CompositionNode(FormulaWrapper("H"), 0.043) ) self.assertEqual(0.7, fuel["C"])
def test_maxco_pointc_o2(self): f = Composition(("C", 0.7), ("H", 0.043), ("O", 0.075), ("N", 0.013)) ocal = OstwaldCalculations(f, 6, 2) self.assertEqual(8.6, round(ocal.C.o2, 1))
def test_kmax_s75(self): f = Composition(("C", 0.7), ("H", 0.043), ("O", 0.075), ("N", 0.013)) ocal = OstwaldCalculations(f, 6, 2) self.assertEqual(18.83, round(ocal.kmax, 2))
def test_v0_s79(self): f = Composition(("C", 0.5921), ("H", 0.0377), ("S", 0.0211), ("O", 0.112), ("N", 0.0128)) m = Mollier(f) self.assertAlmostEqual(5.964, m.vo, delta=0.01)
def test_vocoh2o(self): f = Composition(("C", 0.7), ("H", 0.043), ("O", 0.075), ("N", 0.013)) m = Mollier(f) self.assertEqual(0.842, round(m.Ocoh2o, 3)) # the book says 8.843 but it should be 0.842
def test_ot(self): f = Composition(("C", 0.7), ("H", 0.043), ("O", 0.075), ("N", 0.013)) m = Mollier(f) self.assertEqual(1.496, round(m.Ot, 3))
def test_proportion_of_formula_returns_0_when_nothing_found(self): fuel = Composition( ("S", 0.11), ("CH4", 0.10) ) self.assertEqual(0, fuel.proportion_of_formula("not_existing_formula"))
def test_proportion_of_formula_not_matching_capitalization(self): fuel = Composition( ("S", 0.11), ("CH4", 0.10) ) self.assertEqual(0.10, fuel.proportion_of_formula("Ch4"))
def test_proportion_of_formula(self): fuel = Composition( ("S", 0.11), ("CH4", 0.10) ) self.assertEqual(0.10, fuel.proportion_of_formula("CH4"))
def test_is_gas_false_when_CH_prop_is_0(self): fuel = Composition( ("S", 0.11), ("CH4", 0) ) self.assertEqual(False, fuel.is_gas)
def test_is_gas_false_when_not_gas(self): fuel = Composition( ("S", 0.11), ("C", 0.11) ) self.assertEqual(False, fuel.is_gas)
def test_vo2_84(self): f = Composition(("CH4", 0.958), ("C2H4", 0.008), ("CO", 0.004), ("O2", 0.002), ("CO2", 0.006), ("N2", 0.022)) m = Mollier(f) self.assertAlmostEqual(0.489, m.vo2, delta=0.01)
def test_ot_79(self): f = Composition(("C", 0.5921), ("H", 0.0377), ("S", 0.0211), ("O", 0.112), ("N", 0.0128)) m = Mollier(f) self.assertAlmostEqual(1.253, m.Ot, delta=0.01)
def test_v0(self): f = Composition(("C", 0.7), ("H", 0.043), ("O", 0.075), ("N", 0.013)) m = Mollier(f) self.assertEqual(7.122, round(m.vo, 3))
def test_maxco_s84(self): f = Composition(("CH4", 0.958), ("C2H4", 0.008), ("CO", 0.004), ("O2", 0.002), ("CO2", 0.006), ("N2", 0.022)) ocal = OstwaldCalculations(f, 6, 2) self.assertEqual(15.25, round(ocal.max_co, 2))
def test_vco(self): f = Composition(("C", 0.7), ("H", 0.043), ("O", 0.075), ("N", 0.013)) m = Mollier(f) self.assertEqual(1.308, round(m.vco, 3))
def test_maxco_s75(self): f = Composition(("C", 0.7), ("H", 0.043), ("O", 0.075), ("N", 0.013)) ocal = OstwaldCalculations(f, 6, 2) self.assertEqual(29.16, round(ocal.max_co, 2))
def test_n2(self): f = Composition(("C", 0.7), ("H", 0.043), ("O", 0.075), ("N", 0.013)) m = Mollier(f) self.assertEqual(5.637, round(m.vn2, 3))
def test_kmax_s79(self): f = Composition(("C", 0.5921), ("H", 0.0377), ("S", 0.0211), ("O", 0.112), ("N", 0.0128)) ocal = OstwaldCalculations(f, 6, 2) self.assertEqual(19.17, round(ocal.kmax, 2))
def test_vo0s(self): f = Composition(("C", 0.7), ("H", 0.043), ("O", 0.075), ("N", 0.013)) m = Mollier(f) self.assertEqual(7.6, round(m.v0s, 1))
def test_init_with_empty_list_returns0(self): fuel = Composition() self.assertEqual(0, fuel["O"])
def test_ot_formula_84(self): f = Composition(("CH4", 0.958), ("C2H4", 0.008), ("CO", 0.004), ("O2", 0.002), ("CO2", 0.006), ("N2", 0.022)) m = Mollier(f) self.assertAlmostEqual(1.94, m.Ot, delta=0.01)
def test_vo2(self): f = Composition(("C", 0.7), ("H", 0.043), ("O", 0.075), ("N", 0.013)) m = Mollier(f) self.assertEqual(0.654, round(m.vo2, 3))
def test_creates_composition_nodes_from_tuples_on_init(self): fuel = Composition( ("H", 1) ) self.assertEqual(1, fuel["H"])