def test_addition(self): """Test addition of two element to mass fraction maps. """ hydrogen = pyseawater.Element('H', 1, 1.) oxygen = pyseawater.Element('O', 8, 16.) fractions = pyseawater._fractions2dict( pyseawater.MassFractions({hydrogen: 0.25}) + pyseawater.MassFractions({hydrogen: 0.25}) + pyseawater.MassFractions({oxygen: 0.5})) fractions = {(element.symbol, element.charge, element.weight): fraction for element, fraction in fractions.items()} self.assertDictEqual(fractions, { ('H', 1, 1.): 0.5, ('O', 8, 16.): 0.5 })
def test_init(self): """Test element to mass fraction map to dictionary conversions. """ fractions = pyseawater._fractions2dict( pyseawater.MassFractions({pyseawater.Element('H', 1, 1.): 1.})) fractions = {(element.symbol, element.charge, element.weight): fraction for element, fraction in fractions.items()} self.assertDictEqual(fractions, {('H', 1, 1.): 1.})
def test_sum_massfractions_above_one(self): """Test for expected exception from initialization. """ fractions = pyseawater.MassFractions({ self.hydrogen: 0.6, self.oxygen: 0.6 }) with self.assertRaises(ValueError): pyseawater.Medium(fractions, density=1.)
def test_multiplication(self): """Test multiplication of scale and element to mass fraction map. """ hydrogen = pyseawater.Element('H', 1, 1.) fractions = pyseawater._fractions2dict( 2. * pyseawater.MassFractions({hydrogen: 0.5})) fractions = {(element.symbol, element.charge, element.weight): fraction for element, fraction in fractions.items()} self.assertDictEqual(fractions, {('H', 1, 1.): 1.})