Skip to main content

razor_fol/
test_prelude.rs

1use crate::syntax::*;
2use itertools::Itertools;
3use std::{fmt, fs::File, io::Read};
4
5
6pub fn equal_sets<T: Eq>(first: &[T], second: &[T]) -> bool {
7    first.iter().all(|e| second.contains(e)) && second.iter().all(|e| first.contains(e))
8}
9
10// Variables
11pub fn _u() -> V { V::from("u") }
12
13pub fn _v() -> V { V::from("v") }
14
15pub fn _w() -> V { V::from("w") }
16
17pub fn _x() -> V { V::from("x") }
18
19pub fn _x_1() -> V { V::from("x`") }
20
21pub fn _y() -> V { V::from("y") }
22
23pub fn _z() -> V { V::from("z") }
24
25pub fn u() -> Term { V::from("u").into() }
26
27pub fn v() -> Term { V::from("v").into() }
28
29pub fn w() -> Term { V::from("w").into() }
30
31pub fn x() -> Term { V::from("x").into() }
32
33pub fn x_1() -> Term { V::from("x`").into() }
34
35pub fn y() -> Term { V::from("y").into() }
36
37pub fn z() -> Term { V::from("z").into() }
38
39// Functions
40pub fn f() -> F { F::from("f") }
41
42pub fn g() -> F { F::from("g") }
43
44pub fn h() -> F { F::from("h") }
45
46// Constants
47pub fn _a() -> C { C::from("a") }
48
49pub fn _b() -> C { C::from("b") }
50
51pub fn _c() -> C { C::from("c") }
52
53pub fn _d() -> C { C::from("d") }
54
55pub fn a() -> Term { C::from("a").into() }
56
57pub fn b() -> Term { C::from("b").into() }
58
59#[allow(dead_code)]
60pub fn c() -> Term { C::from("c").into() }
61
62// Predicates
63#[allow(non_snake_case)]
64pub fn P() -> Pred { Pred::from("P") }
65
66#[allow(non_snake_case)]
67pub fn Q() -> Pred { Pred::from("Q") }
68
69#[allow(non_snake_case)]
70pub fn R() -> Pred { Pred::from("R") }
71
72pub fn assert_eq_vectors<T: Ord + fmt::Debug>(first: &Vec<T>, second: &Vec<T>) -> () {
73    assert!(first.iter().sorted() == second.iter().sorted());
74}
75
76pub fn assert_eq_sets<T: Eq + fmt::Debug>(first: &Vec<T>, second: &Vec<T>) -> () {
77    assert!(equal_sets(first, second));
78}
79
80pub fn assert_debug_string<T: fmt::Debug>(expected: &str, value: T) {
81    debug_assert_eq!(expected, format!("{:?}", value));
82}
83
84pub fn assert_debug_strings<T: fmt::Debug>(expected: &str, value: Vec<T>) {
85    let mut strings = value.iter().map(|v| format!("{:?}", v));
86    debug_assert_eq!(expected, strings.join("\n"));
87}
88
89pub fn read_theory_from_file(filename: &str) -> Theory {
90    let mut f = File::open(filename).expect("file not found");
91
92    let mut contents = String::new();
93    f.read_to_string(&mut contents)
94        .expect("something went wrong reading the file");
95
96    contents.parse().unwrap()
97}