Exemple #1
0
    def test_gt_operator(self):
        """Test greater than operator.

        """
        hydrogen = pyseawater.Element('H', 1, 1.)
        oxygen = pyseawater.Element('O', 8, 16.)

        message = ("Oxygen is expected to be larger than hydrogen in terms of "
                   "charge.")

        self.assertGreater(oxygen, hydrogen, message)
Exemple #2
0
    def test_lt_operator(self):
        """Test less than operator.

        """
        hydrogen = pyseawater.Element('H', 1, 1.)
        oxygen = pyseawater.Element('O', 8, 16.)

        message = (
            "Hydrogen is expected to be smaller than oxygen in terms of "
            "charge.")

        self.assertLess(hydrogen, oxygen, message)
Exemple #3
0
    def setUp(self):
        """Initialize water medium.

        """
        self.hydrogen = pyseawater.Element('H', 1, 1.)
        self.oxygen = pyseawater.Element('O', 8, 16.)

        self.fractions = pyseawater.mass_fractions(
            pyseawater.Molecule({
                self.hydrogen: 2,
                self.oxygen: 1
            }))

        self.medium = pyseawater.Medium(self.fractions, density=1.)
Exemple #4
0
    def test_weight_exceptions(self):
        """Test expected exceptions from initialization.

        """
        message = "A `weight` of ``0.`` did not raise an exception."

        with self.assertRaises(ValueError, msg=message):
            pyseawater.Element('H', 1, 0.)
Exemple #5
0
    def test_charge_exception(self):
        """Test expected exceptions from initialization.

        """
        message = "A `charge` of ``0`` did not raise an exception."

        with self.assertRaises(ValueError, msg=message):
            pyseawater.Element('H', 0, 1.)
Exemple #6
0
    def test_weight(self):
        """Test property `weight`.

        """
        hydrogen = pyseawater.Element('H', 1, 1.)

        self.assertEqual(
            hydrogen.weight, 1.,
            "The property `weight` is not equal the expected value ``1.``.")
Exemple #7
0
    def test_charge(self):
        """Test property `charge`.

        """
        hydrogen = pyseawater.Element('H', 1, 1.)

        self.assertEqual(
            hydrogen.charge, 1,
            "The property `charge` is not equal the expected value ``1``.")
Exemple #8
0
    def test_symbol(self):
        """Test property `symbol`.

        """
        hydrogen = pyseawater.Element('H', 1, 1.)

        self.assertEqual(
            hydrogen.symbol, 'H',
            "The property `symbol` is not equal the expected value ``'H'``.")
    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
        })
Exemple #10
0
    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.})
Exemple #11
0
    def test_weight(self):
        """Test function `pyseawater.weight`.

        """
        hydrogen = pyseawater.Element("H", 1, 1.)

        self.assertEqual(pyseawater.weight(pyseawater.Molecule({hydrogen: 1})),
                         hydrogen.weight)

        self.assertEqual(pyseawater.weight(pyseawater.Molecule({hydrogen: 2})),
                         2. * hydrogen.weight)
Exemple #12
0
    def test_multiplication(self):
        """Test multiplication of scale and molecule.

        """
        fractions = pyseawater._fractions2dict(
            1. * pyseawater.Molecule({pyseawater.Element('H', 1, 1.): 2}))

        fractions = {(element.symbol, element.charge, element.weight): fraction
                     for element, fraction in fractions.items()}

        self.assertDictEqual(fractions, {('H', 1, 1.): 1.})
Exemple #13
0
    def test_init(self):
        """Test molecule to dictionary conversions.

        """
        molecule = pyseawater._molecule2dict(
            pyseawater.Molecule({pyseawater.Element('H', 1, 1.): 2}))

        molecule = {(element.symbol, element.charge, element.weight): numatoms
                    for element, numatoms in molecule.items()}

        self.assertDictEqual(molecule, {('H', 1, 1.): 2})
Exemple #14
0
    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.})
Exemple #15
0
 def setUp(self):
     self.hydrogen = pyseawater.Element('H', 1, 1.)
     self.oxygen = pyseawater.Element('O', 8, 16.)