This commit is contained in:
Yadunand Prem
2022-10-13 14:19:42 +08:00
parent 82a1f769fe
commit cdc460bdc7
33 changed files with 1080 additions and 0 deletions

55
Lab6/Test5.java Normal file
View File

@@ -0,0 +1,55 @@
import cs2030s.fp.Constant;
import cs2030s.fp.Memo;
public class Test5 {
public static void main(String[] args) {
CS2030STest we = new CS2030STest();
Constant<Boolean> t = new Constant<>() {
public Boolean init() {
return true;
}
};
Constant<Boolean> f = new Constant<>() {
public Boolean init() {
String res = "";
for (int i=0; i<100000; i++) {
res += i;
}
return false;
}
};
Cond cond = new And(new Or(new Bool(t), new Bool(f)), new Not(new Not(new Bool(t))));
we.expect(
"cond",
cond.toString(),
"((? | ?) & !(!(?)))"
);
we.expect(
"cond.neg()",
cond.neg().toString(),
"((!(?) & !(?)) | !(?))"
);
we.expect(
"cond.neg().neg()",
cond.neg().neg().toString(),
"((? | ?) & ?)"
);
we.expect(
"cond.eval()",
cond.eval(),
true
);
we.expect(
"cond.neg()",
cond.neg().toString(),
"((!(t) & !(?)) | !(t))"
);
we.expect(
"cond.neg().neg()",
cond.neg().neg().toString(),
"((t | ?) & t)"
);
}
}