update tests to properly reflect answer order.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rusty-wam"
|
||||
version = "0.7.4"
|
||||
version = "0.7.5"
|
||||
authors = ["Mark Thom"]
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -300,7 +300,7 @@ pub enum Term {
|
||||
}
|
||||
|
||||
pub enum InlinedQueryTerm {
|
||||
CompareNumber(CompareNumberQT, Vec<Box<Term>>),
|
||||
CompareNumber(CompareNumberQT, Vec<Box<Term>>),
|
||||
IsAtomic(Vec<Box<Term>>),
|
||||
IsVar(Vec<Box<Term>>),
|
||||
IsInteger(Vec<Box<Term>>)
|
||||
@@ -309,7 +309,7 @@ pub enum InlinedQueryTerm {
|
||||
impl InlinedQueryTerm {
|
||||
pub fn arity(&self) -> usize {
|
||||
match self {
|
||||
&InlinedQueryTerm::CompareNumber(_, _) => 2,
|
||||
&InlinedQueryTerm::CompareNumber(_, _) => 2,
|
||||
&InlinedQueryTerm::IsAtomic(_) => 1,
|
||||
&InlinedQueryTerm::IsInteger(_) => 1,
|
||||
&InlinedQueryTerm::IsVar(_) => 1,
|
||||
@@ -346,8 +346,8 @@ impl QueryTerm {
|
||||
match self {
|
||||
&QueryTerm::Arg(_) => 3,
|
||||
&QueryTerm::Catch(_) => 3,
|
||||
&QueryTerm::Throw(_) => 1,
|
||||
&QueryTerm::Display(_) => 1,
|
||||
&QueryTerm::Throw(_) => 1,
|
||||
&QueryTerm::DuplicateTerm(_) => 2,
|
||||
&QueryTerm::Functor(_) => 3,
|
||||
&QueryTerm::Inlined(ref term) => term.arity(),
|
||||
@@ -384,8 +384,8 @@ impl<'a> ClauseType<'a> {
|
||||
&ClauseType::Arg => "arg",
|
||||
&ClauseType::CallN => "call",
|
||||
&ClauseType::Catch => "catch",
|
||||
&ClauseType::Deep(_, _, name, _) => name.as_str(),
|
||||
&ClauseType::Display => "display",
|
||||
&ClauseType::Deep(_, _, name, _) => name.as_str(),
|
||||
&ClauseType::DuplicateTerm => "duplicate_term",
|
||||
&ClauseType::Functor => "functor",
|
||||
&ClauseType::Is => "is",
|
||||
@@ -735,7 +735,7 @@ pub enum ArithmeticInstruction {
|
||||
|
||||
pub enum BuiltInInstruction {
|
||||
CleanUpBlock,
|
||||
CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
|
||||
CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
|
||||
EraseBall,
|
||||
Fail,
|
||||
GetArg,
|
||||
@@ -765,9 +765,9 @@ pub enum ControlInstruction {
|
||||
CallN(usize), // arity.
|
||||
CatchCall,
|
||||
CatchExecute,
|
||||
Deallocate,
|
||||
DisplayCall,
|
||||
DisplayExecute,
|
||||
Deallocate,
|
||||
DuplicateTermCall,
|
||||
DuplicateTermExecute,
|
||||
Execute(TabledRc<Atom>, usize),
|
||||
|
||||
@@ -578,12 +578,8 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
|
||||
code
|
||||
}
|
||||
|
||||
fn compile_query_line(&mut self,
|
||||
term: &'a QueryTerm,
|
||||
term_loc: GenContext,
|
||||
code: &mut Code,
|
||||
index: usize,
|
||||
is_exposed: bool)
|
||||
fn compile_query_line(&mut self, term: &'a QueryTerm, term_loc: GenContext,
|
||||
code: &mut Code, index: usize, is_exposed: bool)
|
||||
{
|
||||
self.marker.reset_arg(term.arity());
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ impl<'a> VariableFixtures<'a>
|
||||
// 1. move the use sets of each variable to a local HashMap, use_set
|
||||
// (iterate mutably, swap mutable refs).
|
||||
// 2. drain use_set. For each use set of U, add into the
|
||||
// no-use sets of appropriate variables T /= U.
|
||||
// no-use sets of appropriate variables T =/= U.
|
||||
// 3. Move the use sets back to their original locations in the fixture.
|
||||
// Compute the conflict set of u.
|
||||
|
||||
|
||||
@@ -112,9 +112,9 @@ impl fmt::Display for ControlInstruction {
|
||||
&ControlInstruction::CatchExecute =>
|
||||
write!(f, "execute_catch"),
|
||||
&ControlInstruction::DisplayCall =>
|
||||
write!(f, "call_display"),
|
||||
write!(f, "display_call"),
|
||||
&ControlInstruction::DisplayExecute =>
|
||||
write!(f, "execute_display"),
|
||||
write!(f, "display_execute"),
|
||||
&ControlInstruction::DuplicateTermCall =>
|
||||
write!(f, "call_duplicate_term"),
|
||||
&ControlInstruction::DuplicateTermExecute =>
|
||||
@@ -164,7 +164,7 @@ impl fmt::Display for BuiltInInstruction {
|
||||
&BuiltInInstruction::CleanUpBlock =>
|
||||
write!(f, "clean_up_block"),
|
||||
&BuiltInInstruction::CompareNumber(cmp, ref at_1, ref at_2) =>
|
||||
write!(f, "number_test {}, {}, {} ", cmp, at_1, at_2),
|
||||
write!(f, "number_test {}, {}, {} ", cmp, at_1, at_2),
|
||||
&BuiltInInstruction::DynamicCompareNumber(cmp) =>
|
||||
write!(f, "dynamic_number_test {}", cmp),
|
||||
&BuiltInInstruction::EraseBall =>
|
||||
|
||||
@@ -39,11 +39,7 @@ impl<'a> QueryIterator<'a> {
|
||||
&QueryTerm::Catch(ref terms) => {
|
||||
let state = TermIterState::Clause(0, ClauseType::Catch, terms);
|
||||
QueryIterator { state_stack: vec![state] }
|
||||
},
|
||||
&QueryTerm::Display(ref terms) => {
|
||||
let state = TermIterState::Clause(0, ClauseType::Display, terms);
|
||||
QueryIterator { state_stack: vec![state] }
|
||||
},
|
||||
},
|
||||
&QueryTerm::DuplicateTerm(ref terms) => {
|
||||
let state = TermIterState::Clause(0, ClauseType::DuplicateTerm, terms);
|
||||
QueryIterator { state_stack: vec![state] }
|
||||
@@ -56,11 +52,15 @@ impl<'a> QueryIterator<'a> {
|
||||
let state = TermIterState::Clause(0, ClauseType::Functor, terms);
|
||||
QueryIterator { state_stack: vec![state] }
|
||||
},
|
||||
&QueryTerm::Display(ref terms) => {
|
||||
let state = TermIterState::Clause(0, ClauseType::Display, terms);
|
||||
QueryIterator { state_stack: vec![state] }
|
||||
},
|
||||
&QueryTerm::Inlined(InlinedQueryTerm::CompareNumber(_, ref terms))
|
||||
| &QueryTerm::Is(ref terms) => {
|
||||
let state = TermIterState::Clause(0, ClauseType::Is, terms);
|
||||
QueryIterator { state_stack: vec![state] }
|
||||
},
|
||||
},
|
||||
&QueryTerm::Inlined(InlinedQueryTerm::IsAtomic(ref terms))
|
||||
| &QueryTerm::Inlined(InlinedQueryTerm::IsInteger(ref terms))
|
||||
| &QueryTerm::Inlined(InlinedQueryTerm::IsVar(ref terms)) =>
|
||||
|
||||
Submodule src/prolog/parser updated: 87d3b043bb...aa164cabe6
@@ -6,65 +6,76 @@ use prolog::machine::*;
|
||||
use prolog::parser::toplevel::*;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::mem::swap;
|
||||
|
||||
pub struct TestOutputter {
|
||||
contents: Vec<String>
|
||||
results: Vec<HashSet<String>>,
|
||||
contents: HashSet<String>,
|
||||
focus: String
|
||||
}
|
||||
|
||||
impl TestOutputter {
|
||||
fn cache(&mut self) {
|
||||
self.begin_new_var();
|
||||
|
||||
let mut contents = HashSet::new();
|
||||
swap(&mut contents, &mut self.contents);
|
||||
|
||||
self.results.push(contents);
|
||||
}
|
||||
}
|
||||
|
||||
impl HeapCellValueOutputter for TestOutputter {
|
||||
type Output = HashSet<String>;
|
||||
type Output = Vec<HashSet<String>>;
|
||||
|
||||
fn new() -> Self {
|
||||
TestOutputter { contents: vec![] }
|
||||
TestOutputter { results: vec![],
|
||||
contents: HashSet::new(),
|
||||
focus: String::new() }
|
||||
}
|
||||
|
||||
fn append(&mut self, contents: &str) {
|
||||
if let Some(ref mut result) = self.contents.last_mut() {
|
||||
**result += contents;
|
||||
fn append(&mut self, focus: &str) {
|
||||
self.focus += focus;
|
||||
}
|
||||
|
||||
fn begin_new_var(&mut self) {
|
||||
if !self.focus.is_empty() {
|
||||
let mut focus = String::new();
|
||||
swap(&mut focus, &mut self.focus);
|
||||
|
||||
self.contents.insert(focus);
|
||||
}
|
||||
}
|
||||
|
||||
fn begin_new_var(&mut self) {
|
||||
self.contents.push(String::new());
|
||||
}
|
||||
|
||||
fn result(self) -> Self::Output {
|
||||
self.contents.into_iter().collect()
|
||||
self.results
|
||||
}
|
||||
|
||||
fn ends_with(&self, s: &str) -> bool {
|
||||
if let Some(ref result) = self.contents.last() {
|
||||
result.ends_with(s)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
self.focus.ends_with(s)
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
if let Some(ref result) = self.contents.last() {
|
||||
result.len()
|
||||
} else {
|
||||
0
|
||||
}
|
||||
self.focus.len()
|
||||
}
|
||||
|
||||
fn truncate(&mut self, len: usize) {
|
||||
if let Some(ref mut result) = self.contents.last_mut() {
|
||||
result.truncate(len);
|
||||
}
|
||||
self.focus.truncate(len);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn collect_test_output<'a>(wam: &mut Machine, alloc_locs: AllocVarDict<'a>,
|
||||
mut heap_locs: HeapVarDict<'a>)
|
||||
-> HashSet<String>
|
||||
-> Vec<HashSet<String>>
|
||||
{
|
||||
let mut output = TestOutputter::new();
|
||||
output = wam.heap_view(&heap_locs, output);
|
||||
|
||||
output.cache();
|
||||
|
||||
while let EvalSession::SubsequentQuerySuccess = wam.continue_query(&alloc_locs, &mut heap_locs)
|
||||
{
|
||||
output = wam.heap_view(&heap_locs, output);
|
||||
output.cache();
|
||||
}
|
||||
|
||||
output.result()
|
||||
@@ -72,11 +83,12 @@ pub fn collect_test_output<'a>(wam: &mut Machine, alloc_locs: AllocVarDict<'a>,
|
||||
|
||||
pub fn collect_test_output_with_limit<'a>(wam: &mut Machine, alloc_locs: AllocVarDict<'a>,
|
||||
mut heap_locs: HeapVarDict<'a>, limit: usize)
|
||||
-> HashSet<String>
|
||||
-> Vec<HashSet<String>>
|
||||
{
|
||||
let mut output = TestOutputter::new();
|
||||
output = wam.heap_view(&heap_locs, output);
|
||||
|
||||
output.cache();
|
||||
|
||||
let mut count = 1;
|
||||
|
||||
if count == limit {
|
||||
@@ -86,7 +98,8 @@ pub fn collect_test_output_with_limit<'a>(wam: &mut Machine, alloc_locs: AllocVa
|
||||
while let EvalSession::SubsequentQuerySuccess = wam.continue_query(&alloc_locs, &mut heap_locs)
|
||||
{
|
||||
output = wam.heap_view(&heap_locs, output);
|
||||
|
||||
output.cache();
|
||||
|
||||
count += 1;
|
||||
|
||||
if count == limit {
|
||||
@@ -116,7 +129,7 @@ pub fn submit(wam: &mut Machine, buffer: &str) -> bool
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn submit_query(wam: &mut Machine, buffer: &str, result: HashSet<String>) -> bool
|
||||
pub fn submit_query(wam: &mut Machine, buffer: &str, result: Vec<HashSet<String>>) -> bool
|
||||
{
|
||||
wam.reset();
|
||||
|
||||
@@ -134,8 +147,8 @@ pub fn submit_query(wam: &mut Machine, buffer: &str, result: HashSet<String>) ->
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn submit_query_with_limit(wam: &mut Machine, buffer: &str,
|
||||
result: HashSet<String>, limit: usize)
|
||||
-> bool
|
||||
result: Vec<HashSet<String>>, limit: usize)
|
||||
-> bool
|
||||
{
|
||||
wam.reset();
|
||||
|
||||
@@ -161,8 +174,8 @@ macro_rules! expand_strs {
|
||||
|
||||
#[allow(unused_macros)]
|
||||
macro_rules! assert_prolog_success_with_limit {
|
||||
($wam:expr, $buf:expr, $res:expr, $limit:expr) => (
|
||||
assert!(submit_query_with_limit($wam, $buf, expand_strs!($res), $limit))
|
||||
($wam:expr, $buf:expr, [$($res:expr),*], $limit:expr) => (
|
||||
assert!(submit_query_with_limit($wam, $buf, vec![$(expand_strs!($res)),*], $limit))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -175,8 +188,8 @@ macro_rules! assert_prolog_failure {
|
||||
|
||||
#[allow(unused_macros)]
|
||||
macro_rules! assert_prolog_success {
|
||||
($wam:expr, $query:expr, $res:expr) => (
|
||||
assert!(submit_query($wam, $query, expand_strs!($res)))
|
||||
($wam:expr, $query:expr, [$($res:expr),*]) => (
|
||||
assert!(submit_query($wam, $query, vec![$(expand_strs!($res)),*]))
|
||||
);
|
||||
($wam:expr, $buf:expr) => (
|
||||
assert_eq!(submit($wam, $buf), true)
|
||||
|
||||
1041
src/tests.rs
1041
src/tests.rs
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user