コード例 #1
0
    def dna_test(self, suffix, solution_length):
        """
        assumes chr2* files are in the current directory, containing
        DNA strings. Reads the files with the given suffix, runs
        longest_substring on them, and checks the length of the
        solution.
        """
        s_file = open('data/chr2_first_' + str(suffix))
        t_file = open('data/chr2a_first_' + str(suffix))
        s = s_file.readline()
        t = t_file.readline()

        start_time = time.time()
        ans = substring.longest_substring(s, t)
        end_time = time.time()

        self.assertEqual(len(ans), solution_length)
        print 'time for test', str(suffix) + ': ', end_time - start_time, 'seconds'
コード例 #2
0
    def dna_test(self, suffix, solution_length):
        """
        assumes chr2* files are in the current directory, containing
        DNA strings. Reads the files with the given suffix, runs
        longest_substring on them, and checks the length of the
        solution.
        """
        s_file = open('data/chr2_first_' + str(suffix))
        t_file = open('data/chr2a_first_' + str(suffix))
        s = s_file.readline()
        t = t_file.readline()

        start_time = time.time()
        ans = substring.longest_substring(s, t)
        end_time = time.time()

        self.assertEqual(len(ans), solution_length)
        print('time for test',
              str(suffix) + ': ', end_time - start_time, 'seconds')
コード例 #3
0
 def test1(self):
     ans = substring.longest_substring('','')
     self.assertEqual(ans, '')
コード例 #4
0
 def test4(self):
     ans = substring.longest_substring('the quick brown fox','THE QUICK BROWN FOX')
     self.assertEqual(ans, ' ')
コード例 #5
0
 def test3(self):
     ans = substring.longest_substring('aaa','aaa')
     self.assertEqual(ans, 'aaa')
コード例 #6
0
 def test4(self):
     ans = substring.longest_substring('the quick brown fox',
                                       'THE QUICK BROWN FOX')
     self.assertEqual(ans, ' ')
コード例 #7
0
 def test3(self):
     ans = substring.longest_substring('aaa', 'aaa')
     self.assertEqual(ans, 'aaa')
コード例 #8
0
 def test1(self):
     ans = substring.longest_substring('', '')
     self.assertEqual(ans, '')