示例#1
0
 def test_encode(self):
     self.assertEqual(solution(encode3.splitlines()), "KQF")
     self.assertEqual(solution(encode23.splitlines()),
                      "ALWAURKQEQQWLRAWZHUYKVN")
     self.assertEqual(solution(encode21.splitlines()),
                      "PQSACVVTOISXFXCIAMQEM")
     self.assertEqual(solution(encode42.splitlines()),
                      "PQSACVVTOISXFXCIAMQEMDZIXFJJSTQIENEFQXVZYV")
示例#2
0
def test_n_ways():
    """
        see: https://oeis.org/A261155
    """
    sequence = [
        11, 16, 19, 23, 26, 29, 32, 34, 37, 39, 41, 44, 46, 47, 49, 51, 53, 54,
        56, 58, 59, 61, 62, 64, 65, 67, 68, 69, 71, 72, 74, 74, 76, 77, 79, 79,
        81, 82, 83, 84, 86, 86, 88, 89, 89, 91, 92, 93, 94
    ]

    for i in range(len(sequence)):
        if sequence[i] == sequence[i - 1]:
            assert len(solution(sequence[i])) == i
            continue
        assert len(solution(sequence[i])) == i + 1
示例#3
0
    def test_overlapping_2(self):
        readings = '''10
        2
        1 4
        2 3'''

        self.assertEqual(solution(readings), [[0, 1], [4, 10]])
示例#4
0
文件: opt.py 项目: KudrinMatvey/opt
    def Minimize(self, lb, rb, r, method, max_iter=None, eps=None):
        self._sol = solution()
        self._sol.points = []
        intervals = list()
        lipsh = None

        if self.__CorrectnessParameters(lb, rb, r, max_iter, method):
            self.__InitializeData(lb, rb, r, max_iter, method, eps)
        else:
            raise TypeError("Invalid type of parameters")

        method = self._methods[method]
        initial_intervals = interval((lb, self.Func(lb)), (rb, self.Func(rb)))
        self._sol.points.append((lb, self.Func(lb)))
        self._sol.points.append((rb, self.Func(rb)))
        self.__UpdateMinValue(initial_intervals.GetILb(),
                              initial_intervals.GetIRb())
        intervals.append(initial_intervals)
        while True:
            if self._spent_iter == self._max_iter:
                self._sol.minimum = self._minimum
                return self._sol
            if type(intervals) is int:
                self._sol.minimum = self._minimum
                return self._sol
            self.__IncreaseIterCount()
            self._sol.spent_iter = self._spent_iter
            lipsh = self.__GetLipsh(intervals)
            for iterv in intervals:
                method(iterv, lipsh)
            intervals = self.__GetNewIntervals(intervals, lipsh, method)
示例#5
0
    def test_tournament_3(self):
        sut = solution(feed3)

        sut.tournament()

        self.assertEqual(1, len(sut.opponents))
        self.assertEqual(10, sut.getWinner().id)
        self.assertEqual([30, 31, 20, 11, 15], sut.getWinner().opponents)
示例#6
0
    def test_tournament_1(self):
        sut = solution(feed1)

        sut.tournament()

        self.assertEqual(1, len(sut.opponents))
        self.assertEqual("2", sut.getWinner().idToString())
        self.assertEqual(["6", "5", "1"], sut.getWinner().opponentsToString())
示例#7
0
    def test_tournament_2(self):
        sut = solution(feed2)

        sut.tournament()

        self.assertEqual(1, len(sut.opponents))
        self.assertEqual(1, sut.getWinner().id)
        self.assertEqual([2], sut.getWinner().opponents)
示例#8
0
    def test_tournament_4(self):
        sut = solution(feed4)

        sut.tournament()

        self.assertEqual(1, len(sut.opponents))
        self.assertEqual(128, sut.getWinner().id)
        self.assertEqual([75, 2, 10, 29, 6, 1, 3], sut.getWinner().opponents)
示例#9
0
 def test_long_fence(self):
     readings = '''2000000000
     5
     2 4
     6 10
     7 8
     3 7
     8 12'''
     self.assertEqual(solution(readings), [[0, 2], [12, 2000000000]])
示例#10
0
    def test_tournament_5(self):
        sut = solution(feed5)

        sut.tournament()

        self.assertEqual(1, len(sut.opponents))
        self.assertEqual(34, sut.getWinner().id)
        self.assertEqual([45, 262, 229, 823, 283, 152, 24, 228, 230, 188],
                         sut.getWinner().opponents)
示例#11
0
 def test_all_painted(self):
     readings = '''12
     5
     6 10
     0 4
     7 8
     3 7
     8 12'''
     self.assertEqual(solution(readings), [])
示例#12
0
def test_one_way():
    assert solution(3) == ["0 0 1"]
    assert solution(5) == ["1 0 0"]
    assert solution(6) == ["0 0 2"]
    assert solution(7) == ["1 1 0"]
    assert solution(8) == ["1 0 1"]
    assert solution(9) == ["0 0 3"]
    assert solution(11) == ["1 0 2"]
示例#13
0
 def __init__(self):
     self._lb = None
     self._rb = None
     self._r = None
     self._max_iter = 100
     self._minimum = None
     self._spent_iter = 0
     self._eps = 0.01
     self._sol = solution()
     self._use_method = None
     self._a = None
     self._b = None
     self._c = None
     self._d = None
示例#14
0
 def test_continuous(self):
     readings = '''100
     10
     2 3
     3 20
     20 30
     30 40
     41 60
     60 70
     70 88
     88 99
     99 100
     40 41'''
     self.assertEqual(solution(readings), [
         [0, 2],
     ])
示例#15
0
 def test_overlapping_1(self):
     readings = '''10
     2
     1 4
     3 5'''
     self.assertEqual(solution(readings), [[0, 1], [5, 10]])
示例#16
0
def test_A():
    assert myFormat(solution(readings1)) == "A2\nB1\nC3"
示例#17
0
def test_E():
    expectation = "A1\nB3\nC0\nD5\nE2\nF7\nG4\nH9\nI6\nJ8"
    assert myFormat(solution(readings4)) == expectation
示例#18
0
def test_sample_9():
    assert solution(createLines(sample9)) == 42
示例#19
0
def test_sample_7():
    assert solution(createLines(sample7)) == 22281
示例#20
0
 def test_case_0(self):
     self.assertEqual(solution(cases[0]["input"].splitlines()),
                      cases[0]["expectation"])
示例#21
0
 def test_first_case(self):
     self.assertTrue(solution(correct).is_correct())
示例#22
0
 def setUp(self):
     self.sut = solution(correct, 9)
示例#23
0
 def test_example(self):
     readings = '''10
     2
     1 4
     5 6'''
     self.assertEqual(solution(readings), [[0, 1], [4, 5], [6, 10]])
示例#24
0
def test_sample_6():
    assert solution(createLines(sample6)) == 0
示例#25
0
def test_C():
    assert myFormat(solution(readings3)) == "P3\nQ7\nR8\nS5\nT6\nU2\nV4\nW1"
示例#26
0
def test_sample_8():
    assert solution(createLines(sample8)) == 18431
示例#27
0
def test_D():
    assert myFormat(
        solution(readings4)) == "A1\nB3\nC0\nD5\nE2\nF7\nG4\nH9\nI6\nJ8"
示例#28
0
def test_sample_5():
    assert solution(createLines(sample5)) == 25
示例#29
0
    def test_decode(self):
        self.assertEqual(solution(decode21.splitlines()),
                         "EVERYONEISWELCOMEHERE")

        self.assertEqual(solution(decode49.splitlines()),
                         "THEQUICKBROWNFOXJUMPSOVERALAZYSPHINXOFBLACKQUARTZ")
示例#30
0
def test_B():
    assert myFormat(solution(readings2)) == "A3\nB5\nC1\nD2\nE4"