Skip to content

Commit

Permalink
Add Pullup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maumagnaguagno committed May 2, 2024
1 parent 99d7883 commit c941b64
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ jobs:
- run: ruby tests/frenesi.rb
- run: ruby tests/again.rb
- run: ruby tests/dependent.rb
- run: ruby tests/logic_high.rb
- run: ruby tests/miner.rb
- run: ruby tests/painter.rb
- run: ruby tests/paisley.rb
- run: ruby tests/polyglot.rb
- run: ruby tests/rescue.rb
- run: ruby tests/simple.rb
- run: ruby tests/walker.rb
Expand Down
105 changes: 105 additions & 0 deletions tests/logic_high.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
require 'test/unit'
require './extensions/Pullup'

class Logic_High < Test::Unit::TestCase

def operators_o1(precond_pos = nil, precond_not = nil)
[
['o1', ['?x'],
# Preconditions
[*precond_pos],
[*precond_not],
# Effects
[['p1', '?x']],
[['p2', '?x']]
]
]
end

def methods_m1(precond_pos = nil, precond_not = nil)
[
['m1', ['?a'],
['case_0', [],
# Preconditions
[*precond_pos],
[*precond_not],
# Subtasks
[['o1', '?a']]
]
]
]
end

def test_pullup_no_tasks
operators = operators_o1
methods = methods_m1
Pullup.apply(operators, methods, predicates = {'p1' => true, 'p2' => true}, state = {'p1' => [], 'p2' => []}, tasks = [], [], [])
assert_equal(operators_o1, operators)
assert_equal(methods_m1, methods)
assert_equal({'p1' => true, 'p2' => true}, predicates)
assert_equal({'p1' => [], 'p2' => []}, state)
assert_true(tasks.empty?)
end

def test_pullup_no_effect_with_operator_task
operators = operators_o1
methods = methods_m1
Pullup.apply(operators, methods, predicates = {'p1' => true, 'p2' => true}, state = {'p1' => [], 'p2' => []}, tasks = [true, ['o1', 'a']], [], [])
assert_equal(operators_o1, operators)
assert_equal(methods_m1, methods)
assert_equal({'p1' => true, 'p2' => true}, predicates)
assert_equal({'p1' => [], 'p2' => []}, state)
assert_equal([true, ['o1', 'a']], tasks)
end

def test_pullup_no_effect_with_method_task
operators = operators_o1
methods = methods_m1
Pullup.apply(operators, methods, predicates = {'p1' => true, 'p2' => true}, state = {'p1' => [], 'p2' => []}, tasks = [true, ['m1', 'a']], [], [])
assert_equal(operators_o1, operators)
assert_equal(methods_m1, methods)
assert_equal({'p1' => true, 'p2' => true}, predicates)
assert_equal({'p1' => [], 'p2' => []}, state)
assert_equal([true, ['m1', 'a']], tasks)
end

def test_pullup_impossible_precondition_with_operator_task
operators = operators_o1
methods = methods_m1([['p3']])
Pullup.apply(operators, methods, predicates = {'p1' => true, 'p2' => true, 'p3' => false}, state = {'p1' => [], 'p2' => []}, tasks = [true, ['o1', 'a']], [], [])
assert_equal(operators_o1, operators)
assert_true(methods.empty?)
assert_equal({'p1' => true, 'p2' => true, 'p3' => nil}, predicates)
assert_equal({'p1' => [], 'p2' => []}, state)
assert_equal([true, ['o1', 'a']], tasks)
end

def test_pullup_impossible_precondition_with_method_task
operators = operators_o1
methods = methods_m1([['p3']])
e = assert_raises(RuntimeError) {Pullup.apply(operators, methods, predicates = {'p1' => true, 'p2' => true, 'p3' => false}, state = {'p1' => [], 'p2' => []}, tasks = [true, ['m1', 'a']], [], [])}
assert_equal('Domain defines no decomposition for m1', e.message)
end

def test_pullup_single_operator_subtask_with_operator_task
operators = operators_o1([['p1', 'a']], [['p1', 'b']])
methods = methods_m1
Pullup.apply(operators, methods, predicates = {'p1' => true, 'p2' => true}, state = {'p1' => [], 'p2' => []}, tasks = [true, ['o1', 'a']], [], [])
assert_equal(operators_o1([['p1', 'a']], [['p1', 'b']]), operators)
assert_equal(methods_m1([['p1', 'a']], [['p1', 'b']]), methods)
assert_equal({'p1' => true, 'p2' => true}, predicates)
assert_equal({'p1' => [], 'p2' => []}, state)
assert_equal([true, ['o1', 'a']], tasks)
end

def test_pullup_single_operator_subtask_with_method_task
operators = operators_o1([['p1', 'a']], [['p1', 'b']])
methods = methods_m1
Pullup.apply(operators, methods, predicates = {'p1' => true, 'p2' => true}, state = {'p1' => [], 'p2' => []}, tasks = [true, ['m1', 'a']], [], [])
assert_equal(operators_o1, operators)
assert_equal(methods_m1([['p1', 'a']], [['p1', 'b']]), methods)
assert_equal({'p1' => true, 'p2' => true}, predicates)
assert_equal({'p1' => [], 'p2' => []}, state)
assert_equal([true, ['m1', 'a']], tasks)
end
end

0 comments on commit c941b64

Please sign in to comment.