示例#1
0
    def assertSmoothingValid(self, path, newpath_expected):
        path_persistent = [pair[:] for pair in path]

        newpath = task.smooth(path)

        self.assertTrue(
            type(newpath) == type(newpath_expected),
            "Function doesn't return a list")
        self.assertTrue(
            len(newpath) == len(newpath_expected),
            "Newpath has the wrong length")
        self.assertEqual(path, path_persistent,
                         "Original path variable was modified by your code")
        for index, got, expected in zip(range(len(newpath_expected)), newpath,
                                        newpath_expected):
            self.assertTrue(
                type(got) == type(expected),
                "Returned list doesn't contain a point at position %d" % index)
            self.assertTrue(
                len(got) == len(expected),
                "Returned list doesn't contain a list of two coordinates "
                "at position %d" % index)
            self.assertAlmostEqual(
                got[0], expected[0], 3, "X coordinate differs for point %d: "
                "expected %.3f, got %.3f" % (index, expected[0], got[0]))
            self.assertAlmostEqual(
                got[1], expected[1], 3, "Y coordinate differs for point %d: "
                "expected %.3f, got %.3f" % (index, expected[1], got[1]))
示例#2
0
    y_answer.append(answer[0][1])

    plt.figure()
    plt.plot(x_path, y_path, 'b-', x_path, y_path, 'bo', x_answer, y_answer,
             'k-')
    plt.axis([min(x_path + x_answer) - 1, max(x_path + x_answer) + 1, \
              min(y_path + y_answer) - 1, max(y_path + y_answer) + 1])


#======================================================================

testpath1 = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [6, 1],
             [6, 2], [6, 3], [5, 3], [4, 3], [3, 3], [2, 3], [1, 3], [0, 3],
             [0, 2], [0, 1]]

answer1 = task.smooth(testpath1)
showpath(testpath1, answer1)

testpath2 = [
    [1, 0],  # Move in the shape of a plus sign
    [2, 0],
    [2, 1],
    [3, 1],
    [3, 2],
    [2, 2],
    [2, 3],
    [1, 3],
    [1, 2],
    [0, 2],
    [0, 1],
    [1, 1]
示例#3
0
      [5, 0],
      [6, 0], #fix
      [6, 1],
      [6, 2],
      [6, 3], #fix
      [5, 3],
      [4, 3],
      [3, 3],
      [2, 3],
      [1, 3],
      [0, 3], #fix
      [0, 2],
      [0, 1]]
testfix1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0]

answer1 = task.smooth(testpath1, testfix1)
showpath(testpath1, testfix1, answer1)

testpath2 = [[0, 0], # fix
             [2, 0],
             [4, 0], # fix
             [4, 2],
             [4, 4], # fix
             [2, 4],
             [0, 4], # fix
             [0, 2]]
testfix2 = [1, 0, 1, 0, 1, 0, 1, 0]

answer2 = task.smooth(testpath2, testfix2)
showpath(testpath2, testfix2, answer2)