Ejemplo n.º 1
0
    def test_calculateAvgHwy(self):
        try:
            from hwy_mpg import calculateAvgHwy
            result = calculateAvgHwy("../files/mpg.csv")
            self.assertEqual(16.87878787878788, result[0][1])
            self.assertEqual("pickup", result[0][0])

            self.assertEqual(18.129032258064516, result[1][1])
            self.assertEqual("suv", result[1][0])

            self.assertEqual(22.363636363636363, result[2][1])
            self.assertEqual("minivan", result[2][0])

            self.assertEqual(24.8, result[3][1])
            self.assertEqual("2seater", result[3][0])

            self.assertEqual(27.29268292682927, result[4][1])
            self.assertEqual("midsize", result[4][0])

            self.assertEqual(28.142857142857142, result[5][1])
            self.assertEqual("subcompact", result[5][0])

            self.assertEqual(28.29787234042553, result[6][1])
            self.assertEqual("compact", result[6][0])
            self.assertTrue(succeed("calculateAvgHwy"))
        except ImportError:
            self.assertFalse(no_function_found("calculateAvgHwy"))
        except AssertionError:
            self.assertFalse(incorrect_output())
 def test_letterAndDigit(self):
     try:
         from letter_digit import letterAndDigit
         result = letterAndDigit('hello world! 123')
         self.assertEqual(3, result['DIGITS'])
         self.assertEqual(10, result['LETTERS'])
         self.assertTrue(succeed("letterAndDigit"))
     except ImportError:
         self.assertFalse(no_function_found("letterAndDigit"))
     except AssertionError:
         self.assertFalse(incorrect_output())
 def test_squareOfNumbers(self):
     try:
         from square_of_numbers import squareOfNumbers
         result = squareOfNumbers(8)
         if isinstance(result, dict):
             self.assertEqual(result[1], 1)
             self.assertEqual(result[2], 4)
             self.assertEqual(result[3], 9)
             self.assertEqual(result[4], 16)
             self.assertEqual(result[5], 25)
             self.assertEqual(result[6], 36)
             self.assertEqual(result[7], 49)
             self.assertEqual(result[8], 64)
             self.assertTrue(succeed("squareOfNumbers"))
         else:
             self.assertFalse(incorrect_output())
     except ImportError:
         self.assertFalse(no_function_found("squareOfNumbers"))
     except AssertionError:
         self.assertFalse(incorrect_output())
Ejemplo n.º 4
0
 def test_deposit_savings(self):
     try:
         from account import Savings
         sa = Savings("123")
         try:
             sa.deposit(1500)
         except:
             self.assertFalse(no_function_found("deposit"))
         self.assertEqual(1500, sa.balance)
         self.assertTrue(succeed("Savings.deposit"))
     except ImportError:
         self.assertFalse(no_function_found("Savings"))
     except AssertionError:
         self.assertFalse(incorrect_output())
Ejemplo n.º 5
0
 def test_deposit_current(self):
     try:
         from account import Current
         ca = Current("456")
         try:
             ca.deposit(20000)
         except:
             self.assertFalse(no_function_found("Savings.deposit"))
         self.assertEqual(20000, ca.balance)
         self.assertTrue(succeed("Savings.deposit"))
     except ImportError:
         self.assertFalse(no_function_found("Current"))
     except AssertionError:
         self.assertFalse(incorrect_output())
    def test_countWord(self):
        try:
            from count_word import countWord
            result = countWord('../files/testfile.txt', 'dummy')
            self.assertEqual(2, result)

            result1 = countWord('../files/testfile.txt', 'Lorem')
            self.assertEqual(2, result1)
            self.assertTrue(succeed("countWord"))
        except ImportError:
            self.assertFalse(no_function_found("countWord"))
        except AssertionError:
            self.assertFalse(incorrect_output())
        except FileExistsError:
            self.assertFalse(no_function_found("file not found"))
    def test_prime_numbers(self):
        try:
            from prime_numbers import get_prime_numbers
        except ImportError:
            self.assertFalse(no_function_found("get_prime_numbers"))

        result = get_prime_numbers(10)
        try:
            self.assertEqual(2, result[0])
            self.assertEqual(3, result[1])
            self.assertEqual(5, result[2])
            self.assertEqual(7, result[3])
            self.assertTrue(succeed("Test cases passed"))
        except:
            self.assertFalse(
                incorrect_output(
                    "function should return array of prime numbers"))
Ejemplo n.º 8
0
    def test_widraw_current(self):
        try:
            from account import Current
            ca = Current("456")
            try:
                ca.deposit(20000)
            except:
                self.assertFalse(no_function_found("Current.deposit"))

            try:
                ca.withdraw(1)
            except:
                self.assertFalse(no_function_found("Current.widraw"))

            self.assertEqual(19998.9, ca.balance)
            self.assertTrue(succeed("Current.deposit"))
        except ImportError:
            self.assertFalse(no_function_found("Current"))
        except AssertionError:
            self.assertFalse(incorrect_output())
    def test_calculateAvgHwy(self):
        try:
            from hwy_mpg import calculateAvgHwy
            result = calculateAvgHwy(
                "./files/mpg.csv"
            )  # result => A dict object -> {'pickup':16.78, 'suv':'18.1290','minivan':22.363, ...}

            self.assertAlmostEqual(16.87878787878788,
                                   result["pickup"],
                                   places=3)

            self.assertAlmostEqual(18.129032258064516, result["suv"], places=3)

            self.assertAlmostEqual(22.363636363636363,
                                   result["minivan"],
                                   places=3)

            self.assertAlmostEqual(24.8, result["2seater"], places=3)

            self.assertAlmostEqual(27.29268292682927,
                                   result["midsize"],
                                   places=3)

            self.assertAlmostEqual(28.142857142857142,
                                   result["subcompact"],
                                   places=3)

            self.assertAlmostEqual(28.29787234042553,
                                   result["compact"],
                                   places=3)

            self.assertTrue(succeed("calculateAvgHwy"))
        except ImportError:
            self.assertFalse(no_function_found("calculateAvgHwy"))
        except AssertionError:
            self.assertFalse(incorrect_output())