示例#1
0
  def _createProgram():
    root = Node("=")
    root.left = Node("y")
    root.right = Node("+")
    root.right.left = Node("y")
    root.right.right = Node("3")

    return Program(root)
示例#2
0
  def testComputeFitnessDOA(self):
    root = Node("=")
    root.left = Node("x")
    root.right = Node("4")

    program = Program(root)

    fitness = FitCurveProblem.computeFitness(program)
    self.assertEqual(fitness, 0.019999999732933336)
示例#3
0
  def testComputeFitnessLow(self):
    root = Node("=")
    root.left = Node("y")
    root.right = Node("4")

    program = Program(root)

    fitness = FitCurveProblem.computeFitness(program)
    self.assertEqual(fitness, 8.14518041038435)
示例#4
0
    def testComputeFitnessDOA(self):
        root = Node("=")
        root.left = Node("x")
        root.right = Node("4")

        program = Program(root)

        fitness = FitCurveProblem.computeFitness(program)
        self.assertEqual(fitness, 0.019999999732933336)
示例#5
0
    def testComputeFitnessLow(self):
        root = Node("=")
        root.left = Node("y")
        root.right = Node("4")

        program = Program(root)

        fitness = FitCurveProblem.computeFitness(program)
        self.assertEqual(fitness, 8.14518041038435)
示例#6
0
  def testComputeFitnessHigh(self):
    root = Node("=")
    root.left = Node("y")
    root.right = Node("+")
    root.right.left = Node("x")
    root.right.right = Node("4")

    program = Program(root)

    fitness = FitCurveProblem.computeFitness(program)
    self.assertEqual(fitness, 100)
示例#7
0
  def testRunSelfReferencingVariable(self):
    root = Node("=")
    root.left = Node("y")
    root.right = Node("+")
    root.right.left = Node("y")
    root.right.right = Node("3")

    program = Program(root)
    result = program.run({"y": 2})

    self.assertEqual(result["y"], 5)
示例#8
0
    def testComputeFitnessHigh(self):
        root = Node("=")
        root.left = Node("y")
        root.right = Node("+")
        root.right.left = Node("x")
        root.right.right = Node("4")

        program = Program(root)

        fitness = FitCurveProblem.computeFitness(program)
        self.assertEqual(fitness, 100)
示例#9
0
    def testReplaceRoot(self):
        node = Node("1")
        node.left = Node("2")
        node.right = Node("3")
        node.left.left = Node("4")

        value = Node("5")
        node = Node.replace(node, node, value)

        self.assertEqual(node.value, "5")
        self.assertIsNone(node.left)
        self.assertIsNone(node.right)
示例#10
0
  def testRun(self):
    root = Node("=")
    root.left = Node("y")
    root.right = Node("+")
    root.right.left = Node("x")
    root.right.right = Node("4")

    program = Program(root)
    result = program.run({"x": 3})

    self.assertEqual(result["x"], 3)
    self.assertEqual(result["y"], 7)
示例#11
0
  def testReplaceRoot(self):
    node = Node("1")
    node.left = Node("2")
    node.right = Node("3")
    node.left.left = Node("4")

    value = Node("5")
    node = Node.replace(node, node, value)

    self.assertEqual(node.value, "5")
    self.assertIsNone(node.left)
    self.assertIsNone(node.right)