def testSend(self, mockSerial):
        "Test send method"

        # Create the class reference and set up test variables
        whoiMath = WhoiMath()

        # The number we'll give to the send method
        expected_result = 6.24512345

        # The string we're expecting to send along the serial port
        expected_serial_string = str(expected_result)

        # Run it
        whoiMath.send(expected_result)

        # The underlying Serial.write method should have been called once
        # with the expected string.  Use the convenience method
        # `assert_called_once_with` on the patched in mock
        whoiMath.serial.write.assert_called_once_with(expected_serial_string)
    def testDivision(self):
        "Test division"

        whoiMath = WhoiMath()
        min_value = 1
        max_value = 100
        num_samples = 100

        for _ in range(num_samples):
            a = randint(min_value, max_value)
            b = randint(min_value, max_value)

            expected = trusted_division(a, b)
            actual = whoiMath.divide(a, b)

            self.assertEqual(
                expected, actual,
                "%f != %f, Failed test with a=%d b=%d" % (expected, actual, a, b)
            )
class TestWhoiMathDivision(unittest.TestCase):

    def setUp(self):
        self.whoiMath = WhoiMath()
        self.min_value = 1
        self.max_value = 100
        self.num_samples = 100

    def testDivision(self):
        "Test division"

        for _ in range(self.num_samples):
            a = randint(self.min_value, self.max_value)
            b = randint(self.min_value, self.max_value)

            expected = trusted_division(a, b)
            actual = self.whoiMath.divide(a, b)

            self.assertEqual(
                expected, actual,
                "%f!=%f, Failed test with a=%d b=%d" % (expected, actual, a, b)
            )

    def testDivisionSend(self):
        "Test send hook"

        a = 6
        b = 3

        # Create a mock object:
        mockSend = mock.MagicMock()

        # Overwrite the 'send' method with a magicMock object
        self.whoiMath.send = mockSend

        # Run the divide, and 'send' the result.  We only care that send is
        # called.  (We're testing division -- NOT if 'send' works)
        result = self.whoiMath.divide(a, b, send=True)

        self.whoiMath.send.assert_called_once_with(result)
class TestWhoiMathDivision(unittest.TestCase):

    def setUp(self):
        self.whoiMath = WhoiMath()
        self.min_value = 1
        self.max_value = 100
        self.num_samples = 100

    def testDivision(self):
        "Test division"

        for _ in range(self.num_samples):
            a = randint(self.min_value, self.max_value)
            b = randint(self.min_value, self.max_value)

            expected = trusted_division(a, b)
            actual = self.whoiMath.divide(a, b)

            self.assertEqual(
                expected, actual,
                "%f != %f, Failed test with a=%d b=%d" % (expected, actual, a, b)
            )
 def setUp(self):
     self.whoiMath = WhoiMath()
     self.min_value = 1
     self.max_value = 100
     self.num_samples = 100