master > master: codego - unittests

This commit is contained in:
RD 2021-05-15 00:05:26 +02:00
parent 79bfcf57bb
commit 6d774a6a4c

View File

@ -23,25 +23,124 @@ func TestEvalLiteral(test *testing.T) {
var val int
var fml formulae.Formula
var I []string
fml = schema.ParseExpr("A0")
I = []string{"A0"}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
fml = schema.ParseExpr("A0")
I = []string{}
val = recursion.Eval(fml, I)
assert.Equal(0, val)
fml = schema.ParseExpr("! A0")
I = []string{"A0"}
val = recursion.Eval(fml, I)
assert.Equal(0, val)
fml = schema.ParseExpr("! A0")
I = []string{}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
}
func TestEvalComplex1(test *testing.T) {
func TestEvalNegation(test *testing.T) {
var assert = assert.New(test)
var val int
var fml formulae.Formula
var I []string
fml = schema.ParseExpr("A4 || ! A4")
I = []string{}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
fml = schema.ParseExpr("A4 && ! A4")
I = []string{}
val = recursion.Eval(fml, I)
assert.Equal(0, val)
}
func TestEvalConjunction(test *testing.T) {
var assert = assert.New(test)
var val int
var fml formulae.Formula
var I []string
fml = schema.ParseExpr("A0 && A1")
I = []string{"A0"}
val = recursion.Eval(fml, I)
assert.Equal(0, val)
fml = schema.ParseExpr("A0 && A1")
I = []string{"A0", "A1"}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
}
func TestEvalDisjunction(test *testing.T) {
var assert = assert.New(test)
var val int
var fml formulae.Formula
var I []string
fml = schema.ParseExpr("A0 || A1")
I = []string{"A0"}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
fml = schema.ParseExpr("A0 || A1")
I = []string{"A7"}
val = recursion.Eval(fml, I)
assert.Equal(0, val)
}
func TestEvalImplication(test *testing.T) {
var assert = assert.New(test)
var val int
var fml formulae.Formula
var I []string
fml = schema.ParseExpr("A0 -> A1")
I = []string{"A0"}
val = recursion.Eval(fml, I)
assert.Equal(0, val)
fml = schema.ParseExpr("A0 -> A1")
I = []string{"A0", "A1"}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
fml = schema.ParseExpr("A0 -> A1")
I = []string{"A7"}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
}
func TestEvalIff(test *testing.T) {
var assert = assert.New(test)
var val int
var fml formulae.Formula
var I []string
fml = schema.ParseExpr("A0 <-> A1")
I = []string{"A0"}
val = recursion.Eval(fml, I)
assert.Equal(0, val)
fml = schema.ParseExpr("A0 <-> A1")
I = []string{"A0", "A1"}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
fml = schema.ParseExpr("A0 <-> A1")
I = []string{"A7"}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
}
func TestEvalComplex(test *testing.T) {
var assert = assert.New(test)
var val int
var fml formulae.Formula
@ -50,26 +149,24 @@ func TestEvalComplex1(test *testing.T) {
I = []string{"A0", "A2"}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
I = []string{"A0", "A3"}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
I = []string{"A0"}
val = recursion.Eval(fml, I)
assert.Equal(0, val)
I = []string{"A4", "A8"}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
}
func TestEvalComplex2(test *testing.T) {
var assert = assert.New(test)
var val int
var fml formulae.Formula
var I []string
fml = schema.ParseExpr("( ! A0 || (( A0 && A3 ) || ! A2 ))")
I = []string{"A0", "A2"}
val = recursion.Eval(fml, I)
assert.Equal(0, val)
I = []string{"A0", "A3"}
val = recursion.Eval(fml, I)
assert.Equal(1, val)
@ -298,12 +395,14 @@ func TestNNFatoms(test *testing.T) {
nnf_expected = formulae.Atom("A7")
fml = schema.ParseExpr("A7")
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
fml = schema.ParseExpr("!! A7")
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
nnf_expected = formulae.NegatedAtom("A7")
fml = schema.ParseExpr("! A7")
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
fml = schema.ParseExpr("!!! A7")
assert.Equal(nnf_expected.GetExpr(), recursion.NNF(fml).GetExpr())
}