コード例 #1
0
    def test_compare_with_tolerance(self):
        # Test default tolerance '0.001%' (it is relative)
        result = compare_with_tolerance(100.0, 100.0)
        self.assertTrue(result)
        result = compare_with_tolerance(100.001, 100.0)
        self.assertTrue(result)
        result = compare_with_tolerance(101.0, 100.0)
        self.assertFalse(result)
        # Test absolute percentage tolerance
        result = compare_with_tolerance(109.9, 100.0, '10%', False)
        self.assertTrue(result)
        result = compare_with_tolerance(110.1, 100.0, '10%', False)
        self.assertFalse(result)
        # Test relative percentage tolerance
        result = compare_with_tolerance(111.0, 100.0, '10%', True)
        self.assertTrue(result)
        result = compare_with_tolerance(112.0, 100.0, '10%', True)
        self.assertFalse(result)
        # Test absolute tolerance (string)
        result = compare_with_tolerance(109.9, 100.0, '10.0', False)
        self.assertTrue(result)
        result = compare_with_tolerance(110.1, 100.0, '10.0', False)
        self.assertFalse(result)
        # Test relative tolerance (string)
        result = compare_with_tolerance(111.0, 100.0, '0.1', True)
        self.assertTrue(result)
        result = compare_with_tolerance(112.0, 100.0, '0.1', True)
        self.assertFalse(result)
        # Test absolute tolerance (float)
        result = compare_with_tolerance(109.9, 100.0, 10.0, False)
        self.assertTrue(result)
        result = compare_with_tolerance(110.1, 100.0, 10.0, False)
        self.assertFalse(result)
        # Test relative tolerance (float)
        result = compare_with_tolerance(111.0, 100.0, 0.1, True)
        self.assertTrue(result)
        result = compare_with_tolerance(112.0, 100.0, 0.1, True)
        self.assertFalse(result)
        ##### Infinite values #####
        infinity = float('Inf')
        # Test relative tolerance (float)
        result = compare_with_tolerance(infinity, 100.0, 1.0, True)
        self.assertFalse(result)
        result = compare_with_tolerance(100.0, infinity, 1.0, True)
        self.assertFalse(result)
        result = compare_with_tolerance(infinity, infinity, 1.0, True)
        self.assertTrue(result)
        # Test absolute tolerance (float)
        result = compare_with_tolerance(infinity, 100.0, 1.0, False)
        self.assertFalse(result)
        result = compare_with_tolerance(100.0, infinity, 1.0, False)
        self.assertFalse(result)
        result = compare_with_tolerance(infinity, infinity, 1.0, False)
        self.assertTrue(result)
        # Test relative tolerance (string)
        result = compare_with_tolerance(infinity, 100.0, '1.0', True)
        self.assertFalse(result)
        result = compare_with_tolerance(100.0, infinity, '1.0', True)
        self.assertFalse(result)
        result = compare_with_tolerance(infinity, infinity, '1.0', True)
        self.assertTrue(result)
        # Test absolute tolerance (string)
        result = compare_with_tolerance(infinity, 100.0, '1.0', False)
        self.assertFalse(result)
        result = compare_with_tolerance(100.0, infinity, '1.0', False)
        self.assertFalse(result)
        result = compare_with_tolerance(infinity, infinity, '1.0', False)
        self.assertTrue(result)
        # Test absolute tolerance for smaller values
        result = compare_with_tolerance(100.01, 100.0, 0.01, False)
        self.assertTrue(result)
        result = compare_with_tolerance(100.001, 100.0, 0.001, False)
        self.assertTrue(result)
        result = compare_with_tolerance(100.01, 100.0, '0.01%', False)
        self.assertTrue(result)
        result = compare_with_tolerance(100.002, 100.0, 0.001, False)
        self.assertFalse(result)
        result = compare_with_tolerance(0.4, 0.44, 0.01, False)
        self.assertFalse(result)
        result = compare_with_tolerance(100.01, 100.0, 0.010, False)
        self.assertTrue(result)

        # Test complex_number instructor_complex
        result = compare_with_tolerance(0.4, complex(0.44, 0), 0.01, False)
        self.assertFalse(result)
        result = compare_with_tolerance(100.01, complex(100.0, 0), 0.010,
                                        False)
        self.assertTrue(result)
        result = compare_with_tolerance(110.1, complex(100.0, 0), '10.0',
                                        False)
        self.assertFalse(result)
        result = compare_with_tolerance(111.0, complex(100.0, 0), '10%', True)
        self.assertTrue(result)
コード例 #2
0
ファイル: test_util.py プロジェクト: PaoloC68/edx-platform
 def test_compare_with_tolerance(self):
     # Test default tolerance '0.001%' (it is relative)
     result = compare_with_tolerance(100.0, 100.0)
     self.assertTrue(result)
     result = compare_with_tolerance(100.001, 100.0)
     self.assertTrue(result)
     result = compare_with_tolerance(101.0, 100.0)
     self.assertFalse(result)
     # Test absolute percentage tolerance
     result = compare_with_tolerance(109.9, 100.0, '10%', False)
     self.assertTrue(result)
     result = compare_with_tolerance(110.1, 100.0, '10%', False)
     self.assertFalse(result)
     # Test relative percentage tolerance
     result = compare_with_tolerance(111.0, 100.0, '10%', True)
     self.assertTrue(result)
     result = compare_with_tolerance(112.0, 100.0, '10%', True)
     self.assertFalse(result)
     # Test absolute tolerance (string)
     result = compare_with_tolerance(109.9, 100.0, '10.0', False)
     self.assertTrue(result)
     result = compare_with_tolerance(110.1, 100.0, '10.0', False)
     self.assertFalse(result)
      # Test relative tolerance (string)
     result = compare_with_tolerance(111.0, 100.0, '0.1', True)
     self.assertTrue(result)
     result = compare_with_tolerance(112.0, 100.0, '0.1', True)
     self.assertFalse(result)
     # Test absolute tolerance (float)
     result = compare_with_tolerance(109.9, 100.0, 10.0, False)
     self.assertTrue(result)
     result = compare_with_tolerance(110.1, 100.0, 10.0, False)
     self.assertFalse(result)
      # Test relative tolerance (float)
     result = compare_with_tolerance(111.0, 100.0, 0.1, True)
     self.assertTrue(result)
     result = compare_with_tolerance(112.0, 100.0, 0.1, True)
     self.assertFalse(result)
     ##### Infinite values #####
     infinity = float('Inf')
     # Test relative tolerance (float)
     result = compare_with_tolerance(infinity, 100.0, 1.0, True)
     self.assertFalse(result)
     result = compare_with_tolerance(100.0, infinity, 1.0, True)
     self.assertFalse(result)
     result = compare_with_tolerance(infinity, infinity, 1.0, True)
     self.assertTrue(result)
     # Test absolute tolerance (float)
     result = compare_with_tolerance(infinity, 100.0, 1.0, False)
     self.assertFalse(result)
     result = compare_with_tolerance(100.0, infinity, 1.0, False)
     self.assertFalse(result)
     result = compare_with_tolerance(infinity, infinity, 1.0, False)
     self.assertTrue(result)
     # Test relative tolerance (string)
     result = compare_with_tolerance(infinity, 100.0, '1.0', True)
     self.assertFalse(result)
     result = compare_with_tolerance(100.0, infinity, '1.0', True)
     self.assertFalse(result)
     result = compare_with_tolerance(infinity, infinity, '1.0', True)
     self.assertTrue(result)
     # Test absolute tolerance (string)
     result = compare_with_tolerance(infinity, 100.0, '1.0', False)
     self.assertFalse(result)
     result = compare_with_tolerance(100.0, infinity, '1.0', False)
     self.assertFalse(result)
     result = compare_with_tolerance(infinity, infinity, '1.0', False)
     self.assertTrue(result)
コード例 #3
0
ファイル: test_util.py プロジェクト: 10clouds/edx-platform
    def test_compare_with_tolerance(self):
        # Test default tolerance '0.001%' (it is relative)
        result = compare_with_tolerance(100.0, 100.0)
        self.assertTrue(result)
        result = compare_with_tolerance(100.001, 100.0)
        self.assertTrue(result)
        result = compare_with_tolerance(101.0, 100.0)
        self.assertFalse(result)
        # Test absolute percentage tolerance
        result = compare_with_tolerance(109.9, 100.0, '10%', False)
        self.assertTrue(result)
        result = compare_with_tolerance(110.1, 100.0, '10%', False)
        self.assertFalse(result)
        # Test relative percentage tolerance
        result = compare_with_tolerance(111.0, 100.0, '10%', True)
        self.assertTrue(result)
        result = compare_with_tolerance(112.0, 100.0, '10%', True)
        self.assertFalse(result)
        # Test absolute tolerance (string)
        result = compare_with_tolerance(109.9, 100.0, '10.0', False)
        self.assertTrue(result)
        result = compare_with_tolerance(110.1, 100.0, '10.0', False)
        self.assertFalse(result)
        # Test relative tolerance (string)
        result = compare_with_tolerance(111.0, 100.0, '0.1', True)
        self.assertTrue(result)
        result = compare_with_tolerance(112.0, 100.0, '0.1', True)
        self.assertFalse(result)
        # Test absolute tolerance (float)
        result = compare_with_tolerance(109.9, 100.0, 10.0, False)
        self.assertTrue(result)
        result = compare_with_tolerance(110.1, 100.0, 10.0, False)
        self.assertFalse(result)
        # Test relative tolerance (float)
        result = compare_with_tolerance(111.0, 100.0, 0.1, True)
        self.assertTrue(result)
        result = compare_with_tolerance(112.0, 100.0, 0.1, True)
        self.assertFalse(result)
        ##### Infinite values #####
        infinity = float('Inf')
        # Test relative tolerance (float)
        result = compare_with_tolerance(infinity, 100.0, 1.0, True)
        self.assertFalse(result)
        result = compare_with_tolerance(100.0, infinity, 1.0, True)
        self.assertFalse(result)
        result = compare_with_tolerance(infinity, infinity, 1.0, True)
        self.assertTrue(result)
        # Test absolute tolerance (float)
        result = compare_with_tolerance(infinity, 100.0, 1.0, False)
        self.assertFalse(result)
        result = compare_with_tolerance(100.0, infinity, 1.0, False)
        self.assertFalse(result)
        result = compare_with_tolerance(infinity, infinity, 1.0, False)
        self.assertTrue(result)
        # Test relative tolerance (string)
        result = compare_with_tolerance(infinity, 100.0, '1.0', True)
        self.assertFalse(result)
        result = compare_with_tolerance(100.0, infinity, '1.0', True)
        self.assertFalse(result)
        result = compare_with_tolerance(infinity, infinity, '1.0', True)
        self.assertTrue(result)
        # Test absolute tolerance (string)
        result = compare_with_tolerance(infinity, 100.0, '1.0', False)
        self.assertFalse(result)
        result = compare_with_tolerance(100.0, infinity, '1.0', False)
        self.assertFalse(result)
        result = compare_with_tolerance(infinity, infinity, '1.0', False)
        self.assertTrue(result)
        # Test absolute tolerance for smaller values
        result = compare_with_tolerance(100.01, 100.0, 0.01, False)
        self.assertTrue(result)
        result = compare_with_tolerance(100.001, 100.0, 0.001, False)
        self.assertTrue(result)
        result = compare_with_tolerance(100.01, 100.0, '0.01%', False)
        self.assertTrue(result)
        result = compare_with_tolerance(100.002, 100.0, 0.001, False)
        self.assertFalse(result)
        result = compare_with_tolerance(0.4, 0.44, 0.01, False)
        self.assertFalse(result)
        result = compare_with_tolerance(100.01, 100.0, 0.010, False)
        self.assertTrue(result)

        # Test complex_number instructor_complex
        result = compare_with_tolerance(0.4, complex(0.44, 0), 0.01, False)
        self.assertFalse(result)
        result = compare_with_tolerance(100.01, complex(100.0, 0), 0.010, False)
        self.assertTrue(result)
        result = compare_with_tolerance(110.1, complex(100.0, 0), '10.0', False)
        self.assertFalse(result)
        result = compare_with_tolerance(111.0, complex(100.0, 0), '10%', True)
        self.assertTrue(result)
コード例 #4
0
ファイル: test_util.py プロジェクト: yrchen/edx-platform
    def test_compare_with_tolerance(self):  # lint-amnesty, pylint: disable=too-many-statements
        # Test default tolerance '0.001%' (it is relative)
        result = compare_with_tolerance(100.0, 100.0)
        assert result
        result = compare_with_tolerance(100.001, 100.0)
        assert result
        result = compare_with_tolerance(101.0, 100.0)
        assert not result
        # Test absolute percentage tolerance
        result = compare_with_tolerance(109.9, 100.0, '10%', False)
        assert result
        result = compare_with_tolerance(110.1, 100.0, '10%', False)
        assert not result
        # Test relative percentage tolerance
        result = compare_with_tolerance(111.0, 100.0, '10%', True)
        assert result
        result = compare_with_tolerance(112.0, 100.0, '10%', True)
        assert not result
        # Test absolute tolerance (string)
        result = compare_with_tolerance(109.9, 100.0, '10.0', False)
        assert result
        result = compare_with_tolerance(110.1, 100.0, '10.0', False)
        assert not result
        # Test relative tolerance (string)
        result = compare_with_tolerance(111.0, 100.0, '0.1', True)
        assert result
        result = compare_with_tolerance(112.0, 100.0, '0.1', True)
        assert not result
        # Test absolute tolerance (float)
        result = compare_with_tolerance(109.9, 100.0, 10.0, False)
        assert result
        result = compare_with_tolerance(110.1, 100.0, 10.0, False)
        assert not result
        # Test relative tolerance (float)
        result = compare_with_tolerance(111.0, 100.0, 0.1, True)
        assert result
        result = compare_with_tolerance(112.0, 100.0, 0.1, True)
        assert not result
        ##### Infinite values #####
        infinity = float('Inf')
        # Test relative tolerance (float)
        result = compare_with_tolerance(infinity, 100.0, 1.0, True)
        assert not result
        result = compare_with_tolerance(100.0, infinity, 1.0, True)
        assert not result
        result = compare_with_tolerance(infinity, infinity, 1.0, True)
        assert result
        # Test absolute tolerance (float)
        result = compare_with_tolerance(infinity, 100.0, 1.0, False)
        assert not result
        result = compare_with_tolerance(100.0, infinity, 1.0, False)
        assert not result
        result = compare_with_tolerance(infinity, infinity, 1.0, False)
        assert result
        # Test relative tolerance (string)
        result = compare_with_tolerance(infinity, 100.0, '1.0', True)
        assert not result
        result = compare_with_tolerance(100.0, infinity, '1.0', True)
        assert not result
        result = compare_with_tolerance(infinity, infinity, '1.0', True)
        assert result
        # Test absolute tolerance (string)
        result = compare_with_tolerance(infinity, 100.0, '1.0', False)
        assert not result
        result = compare_with_tolerance(100.0, infinity, '1.0', False)
        assert not result
        result = compare_with_tolerance(infinity, infinity, '1.0', False)
        assert result
        # Test absolute tolerance for smaller values
        result = compare_with_tolerance(100.01, 100.0, 0.01, False)
        assert result
        result = compare_with_tolerance(100.001, 100.0, 0.001, False)
        assert result
        result = compare_with_tolerance(100.01, 100.0, '0.01%', False)
        assert result
        result = compare_with_tolerance(100.002, 100.0, 0.001, False)
        assert not result
        result = compare_with_tolerance(0.4, 0.44, 0.01, False)
        assert not result
        result = compare_with_tolerance(100.01, 100.0, 0.010, False)
        assert result

        # Test complex_number instructor_complex
        result = compare_with_tolerance(0.4, complex(0.44, 0), 0.01, False)
        assert not result
        result = compare_with_tolerance(100.01, complex(100.0, 0), 0.010,
                                        False)
        assert result
        result = compare_with_tolerance(110.1, complex(100.0, 0), '10.0',
                                        False)
        assert not result
        result = compare_with_tolerance(111.0, complex(100.0, 0), '10%', True)
        assert result
コード例 #5
0
ファイル: test_util.py プロジェクト: uncletomiwa/edx-platform
 def test_compare_with_tolerance(self):
     # Test default tolerance '0.001%' (it is relative)
     result = compare_with_tolerance(100.0, 100.0)
     self.assertTrue(result)
     result = compare_with_tolerance(100.001, 100.0)
     self.assertTrue(result)
     result = compare_with_tolerance(101.0, 100.0)
     self.assertFalse(result)
     # Test absolute percentage tolerance
     result = compare_with_tolerance(109.9, 100.0, '10%', False)
     self.assertTrue(result)
     result = compare_with_tolerance(110.1, 100.0, '10%', False)
     self.assertFalse(result)
     # Test relative percentage tolerance
     result = compare_with_tolerance(111.0, 100.0, '10%', True)
     self.assertTrue(result)
     result = compare_with_tolerance(112.0, 100.0, '10%', True)
     self.assertFalse(result)
     # Test absolute tolerance (string)
     result = compare_with_tolerance(109.9, 100.0, '10.0', False)
     self.assertTrue(result)
     result = compare_with_tolerance(110.1, 100.0, '10.0', False)
     self.assertFalse(result)
     # Test relative tolerance (string)
     result = compare_with_tolerance(111.0, 100.0, '0.1', True)
     self.assertTrue(result)
     result = compare_with_tolerance(112.0, 100.0, '0.1', True)
     self.assertFalse(result)
     # Test absolute tolerance (float)
     result = compare_with_tolerance(109.9, 100.0, 10.0, False)
     self.assertTrue(result)
     result = compare_with_tolerance(110.1, 100.0, 10.0, False)
     self.assertFalse(result)
     # Test relative tolerance (float)
     result = compare_with_tolerance(111.0, 100.0, 0.1, True)
     self.assertTrue(result)
     result = compare_with_tolerance(112.0, 100.0, 0.1, True)
     self.assertFalse(result)
     ##### Infinite values #####
     infinity = float('Inf')
     # Test relative tolerance (float)
     result = compare_with_tolerance(infinity, 100.0, 1.0, True)
     self.assertFalse(result)
     result = compare_with_tolerance(100.0, infinity, 1.0, True)
     self.assertFalse(result)
     result = compare_with_tolerance(infinity, infinity, 1.0, True)
     self.assertTrue(result)
     # Test absolute tolerance (float)
     result = compare_with_tolerance(infinity, 100.0, 1.0, False)
     self.assertFalse(result)
     result = compare_with_tolerance(100.0, infinity, 1.0, False)
     self.assertFalse(result)
     result = compare_with_tolerance(infinity, infinity, 1.0, False)
     self.assertTrue(result)
     # Test relative tolerance (string)
     result = compare_with_tolerance(infinity, 100.0, '1.0', True)
     self.assertFalse(result)
     result = compare_with_tolerance(100.0, infinity, '1.0', True)
     self.assertFalse(result)
     result = compare_with_tolerance(infinity, infinity, '1.0', True)
     self.assertTrue(result)
     # Test absolute tolerance (string)
     result = compare_with_tolerance(infinity, 100.0, '1.0', False)
     self.assertFalse(result)
     result = compare_with_tolerance(100.0, infinity, '1.0', False)
     self.assertFalse(result)
     result = compare_with_tolerance(infinity, infinity, '1.0', False)
     self.assertTrue(result)