示例#1
0
 def test_formatted_time_success(self):
     test = Timer(self.subject)
     test.start()
     time.sleep(.001)
     test.stop()
     duration = test.duration()
     message = "{} lasted {} seconds".format(self.subject, duration)
     self.assertEqual(test.formatted_time(), message)
示例#2
0
 def test_duration(self):
     test = Timer(self.subject)
     test.start()
     time.sleep(.001)
     test.stop()
     duration = test.duration()
     self.assertNotEqual(duration, 0)
    def test_make_distribution(self):
        element_type = "letter"
        dist = self.test.make_distribution(element_type, self.small_test_data)
        self.assertIsInstance(dist, Distribution)

        timer = Timer("big data distribution creation")
        timer.start()
        big_dist = self.test.make_distribution(element_type, self.big_test_data)
        timer.stop()
        print(timer.formatted_time())
    def test_total_method(self):
        small_timer_len = Timer("small_data_len")
        small_timer_loop = Timer("small_data_loop")
        big_timer_len = Timer("big_data_len")
        big_timer_loop = Timer("big_data_loop")

        small_timer_len.start()
        small_total_len = self.test.get_total_count(self.small_test_data)
        small_timer_len.stop()

        small_loop_value_counts = self.test.get_element_frequency(self.small_test_data)
        small_timer_loop.start()
        small_total_loop = self.test.get_element_frequency_total(small_loop_value_counts)
        small_timer_loop.stop()

        big_timer_len.start()
        big_total_len = self.test.get_total_count(self.big_test_data)
        big_timer_len.stop()

        big_loop_value_counts = self.test.get_element_frequency(self.big_test_data)
        big_timer_loop.start()
        big_total_loop = self.test.get_element_frequency_total(big_loop_value_counts)
        big_timer_loop.stop()

        self.assertEqual(len(self.small_test_data), small_total_len)
        self.assertEqual(len(self.small_test_data), small_total_loop)
        self.assertEqual(len(self.big_test_data), big_total_len)
        self.assertEqual(len(self.big_test_data), big_total_loop)

        print(small_timer_len.formatted_time())
        print(small_timer_loop.formatted_time())
        print(big_timer_len.formatted_time())
        print(big_timer_loop.formatted_time())

        small_len_faster = small_timer_len.duration() < small_timer_loop.duration()
        self.assertTrue(small_len_faster)

        big_len_faster = big_timer_len.duration() < big_timer_loop.duration()
        self.assertTrue(big_len_faster)
示例#5
0
 def test_start(self):
     test = Timer(self.subject)
     test.start()
     self.assertNotEqual(test.start_time, 0)
示例#6
0
 def test_formatted_time_stop_error(self):
     test = Timer(self.subject)
     test.start()
     result = test.formatted_time()
     self.assertEqual(result, test.stop_error)
示例#7
0
 def test_end(self):
     test = Timer(self.subject)
     test.stop()
     self.assertNotEqual(test.stop_time, 0)