Skip to content

Commit

Permalink
Add polyglot tests
Browse files Browse the repository at this point in the history
Compilers are expected to not change the intermediate representation.
  • Loading branch information
Maumagnaguagno committed Apr 30, 2024
1 parent 2802547 commit 3d65abf
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/polyglot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require './tests/hypest'

class Polyglot < Test::Unit::TestCase

def intermediate_representation(parser)
[
parser.domain_name,
parser.problem_name,
parser.operators,
parser.methods,
parser.predicates,
parser.state,
parser.tasks,
parser.goal_pos,
parser.goal_not
]
end

def compile(ir)
expected = Marshal.load(Marshal.dump(ir))
[
Hyper_Compiler,
Cyber_Compiler,
JSHOP_Compiler,
HDDL_Compiler,
PDDL_Compiler,
Dot_Compiler,
Markdown_Compiler
].each {|compiler|
next if compiler == Cyber_Compiler and not ir[6][0]
compiler.compile_domain(*ir)
compiler.compile_problem(*ir, nil)
assert_equal(expected, ir)
}
end

def test_basic_pb1_pddl_compilation
PDDL_Parser.parse_domain('examples/basic/basic.pddl')
PDDL_Parser.parse_problem('examples/basic/pb1.pddl')
compile(intermediate_representation(PDDL_Parser))
end

def test_basic_pb1_hddl_compilation
HDDL_Parser.parse_domain('examples/basic/basic.hddl')
HDDL_Parser.parse_problem('examples/basic/pb1.hddl')
compile(intermediate_representation(HDDL_Parser))
end

def test_basic_pb1_jshop_compilation
JSHOP_Parser.parse_domain('examples/basic/basic.jshop')
JSHOP_Parser.parse_problem('examples/basic/pb1.jshop')
compile(intermediate_representation(JSHOP_Parser))
end

def test_tsp_pb1_pddl_compilation
PDDL_Parser.parse_domain('examples/tsp/tsp.pddl')
PDDL_Parser.parse_problem('examples/tsp/pb1.pddl')
compile(ir = intermediate_representation(PDDL_Parser))
Patterns.apply(*ir.drop(2))
compile(ir)
end
end

0 comments on commit 3d65abf

Please sign in to comment.