import unittest
from unittest import TestCase

from misc import verify


class TestVerify(TestCase):
    """Tests misc.py verifies function."""

    def test_verify__with_zero_threshold_and_expected_succeeds(self):
        """Test passes when expected rate, actual rate and threshold are all zero."""
        result = verify(metric="Query failure rate", actual=0.0, expected=0.0, threshold=0.0)
        self.assertEqual(result, 0)

    def test_verify__fails_when_positive_delta_is_larger_than_postive_threshold(self):
        """Test fails when positive delta between actual rate and expected rate exceeds positive threshold."""
        result = verify(metric="Update latency", actual=200, expected=100, threshold=0.1)
        self.assertEqual(result, 1)

    def test_verify__fails_when_negative_delta_is_smaller_than_negative_threshold(self):
        """Test fails when negative delta between actual rate and expected rate exceeds negative threshold."""
        result = verify(metric="Update latency", actual=50, expected=100, threshold=-0.01)
        self.assertEqual(result, 1)

    def test_verify__fails_when_negative_delta_and_positive_threshold(self):
        """Test fails when delta between actual rate and expected rate exceeds threshold."""
        result = verify(metric="Update latency", actual=50, expected=100, threshold=0.01)
        self.assertEqual(result, 0)


if __name__ == "__main__":
    unittest.main()

[((1414, 1429), 'unittest.main', 'unittest.main', ([], {}), '()\n', (1427, 1429), False, 'import unittest\n'), ((318, 394), 'misc.verify', 'verify', ([], {'metric': '"""Query failure rate"""', 'actual': '(0.0)', 'expected': '(0.0)', 'threshold': '(0.0)'}), "(metric='Query failure rate', actual=0.0, expected=0.0, threshold=0.0)\n", (324, 394), False, 'from misc import verify\n'), ((647, 719), 'misc.verify', 'verify', ([], {'metric': '"""Update latency"""', 'actual': '(200)', 'expected': '(100)', 'threshold': '(0.1)'}), "(metric='Update latency', actual=200, expected=100, threshold=0.1)\n", (653, 719), False, 'from misc import verify\n'), ((974, 1047), 'misc.verify', 'verify', ([], {'metric': '"""Update latency"""', 'actual': '(50)', 'expected': '(100)', 'threshold': '(-0.01)'}), "(metric='Update latency', actual=50, expected=100, threshold=-0.01)\n", (980, 1047), False, 'from misc import verify\n'), ((1272, 1344), 'misc.verify', 'verify', ([], {'metric': '"""Update latency"""', 'actual': '(50)', 'expected': '(100)', 'threshold': '(0.01)'}), "(metric='Update latency', actual=50, expected=100, threshold=0.01)\n", (1278, 1344), False, 'from misc import verify\n')]