コード例 #1
0
    def test_comparison_float_absolute_pass(self):
        """Test that comparison of float with absolute tolerance passes when
        it is less that tolerance.

        """
        conf = {}
        comparison = Comparison('unittest', conf)
        category = comparison._tolerances.CONC
        comparison.update_from_name(category, '1.0e-16 absolute')
        section = 'Ca'
        key = 'cell 1'
        a_data = '1.0e-16'
        b_data = '1.1e-16'

        received = comparison._compare_float_values_with_tolerance(
            category, section, key, a_data, b_data)
        self.assertTrue(received)
コード例 #2
0
    def test_comparison_float_percent_fail(self):
        """Test that comparison of float with percent tolerance fails when it
        is greater than tolerance.

        """
        conf = {}
        comparison = Comparison('unittest', conf)
        category = comparison._tolerances.CONC
        comparison.update_from_name(category, '5.0 percent')
        section = 'foo'
        key = 'cell 1'
        a_data = '1.0e-16'
        b_data = '1.06e-16'

        received = comparison._compare_float_values_with_tolerance(
            category, section, key, a_data, b_data)
        self.assertFalse(received)
コード例 #3
0
    def test_compare_values_pass(self):
        """Test that call to compare_values_with_tolerance with valid data
        passes.

        FIXME(bja, 201603) Only way to check this is via the _status
        flag being unset... very bad.

        """
        conf = {}
        comparison = Comparison('unittest', conf)
        category = comparison._tolerances.CONC
        comparison.update_from_name(category, '1.0e-4 relative')
        section = 'foo'
        key = 'cell 1'
        a_data = '1.0e-16'
        b_data = '1.00001e-16'

        comparison._compare_values_with_tolerance(
            category, section, key, a_data, b_data)
        self.assertIsNone(comparison._status)
コード例 #4
0
    def test_comparison_float_invalid_method(self):
        """Test that comparison of float with junk tolerance type fails with
        an exception. Kind of a contrived example because it should be
        very hard to get to this code given all the prior error
        checking.

        """
        conf = {}
        comparison = Comparison('unittest', conf)
        category = comparison._tolerances.CONC
        comparison.update_from_name(category, '5.0 percent')
        comparison._tolerances._tolerances[category]['type'] = 'junk'
        section = 'foo'
        key = 'cell 1'
        a_data = '1.0e-16'
        b_data = '1.06e-16'

        self.assertRaises(RuntimeError,
                          comparison._compare_float_values_with_tolerance,
                          category, section, key, a_data, b_data)