master > master: codego - utils + unit tests, A1[0-9]+ mit testen
This commit is contained in:
parent
2ab9b63a08
commit
f292d7e5dc
@ -205,8 +205,7 @@ func TestAtomsCalc1(test *testing.T) {
|
||||
var val []string
|
||||
fml = schema.ParseExpr("A0")
|
||||
val = recursion.Atoms(fml)
|
||||
utils.SortStrings(&val)
|
||||
assert.Equal([]string{"A0"}, val)
|
||||
assert.ElementsMatch([]string{"A0"}, val)
|
||||
}
|
||||
|
||||
func TestAtomsCalc2(test *testing.T) {
|
||||
@ -216,8 +215,7 @@ func TestAtomsCalc2(test *testing.T) {
|
||||
var val []string
|
||||
fml = schema.ParseExpr("((( ! A8 && A3 ) || A4 ) && A0 )")
|
||||
val = recursion.Atoms(fml)
|
||||
utils.SortStrings(&val)
|
||||
assert.Equal([]string{"A0", "A3", "A4", "A8"}, val)
|
||||
assert.ElementsMatch([]string{"A0", "A3", "A4", "A8"}, val)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- *
|
||||
|
@ -25,8 +25,13 @@ func TestParseExpr(test *testing.T) {
|
||||
assert.Equal("atom", tree.GetKind())
|
||||
assert.Equal(0, len(tree.GetSubFormulae()))
|
||||
|
||||
tree = schema.ParseExpr("A12")
|
||||
assert.Equal("A12", tree.GetExpr())
|
||||
assert.Equal("atom", tree.GetKind())
|
||||
assert.Equal(0, len(tree.GetSubFormulae()))
|
||||
|
||||
tree = schema.ParseExpr(" ! A5 ")
|
||||
assert.Equal("! A5", tree.GetExpr())
|
||||
assert.Equal("!A5", tree.GetExpr())
|
||||
assert.Equal("not", tree.GetKind())
|
||||
assert.Equal(1, len(tree.GetSubFormulae()))
|
||||
|
||||
@ -35,8 +40,8 @@ func TestParseExpr(test *testing.T) {
|
||||
assert.Equal("implies", tree.GetKind())
|
||||
assert.Equal(2, len(tree.GetSubFormulae()))
|
||||
|
||||
tree = schema.ParseExpr("( A0 && A1) || A2")
|
||||
assert.Equal("((A0 && A1) || A2)", tree.GetExpr())
|
||||
tree = schema.ParseExpr("( A0 && ! ! A1) || A2")
|
||||
assert.Equal("((A0 && !!A1) || A2)", tree.GetExpr())
|
||||
assert.Equal("or2", tree.GetKind())
|
||||
assert.Equal(2, len(tree.GetSubFormulae()))
|
||||
}
|
||||
|
@ -85,6 +85,14 @@ func SumList(x []int) int {
|
||||
* METHODS: for string lists
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
func CopyStringList(list []string) []string {
|
||||
var listCopy = make([]string, len(list))
|
||||
for i, value := range list {
|
||||
listCopy[i] = value
|
||||
}
|
||||
return listCopy
|
||||
}
|
||||
|
||||
func StrListContains(list []string, x string) bool {
|
||||
for _, obj := range list {
|
||||
if obj == x {
|
||||
@ -153,3 +161,15 @@ func UnionStringsList(lists [][]string) []string {
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- *
|
||||
* METHODS: for maps
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
func CopyMapStringBool(m map[string]bool) map[string]bool {
|
||||
var mCopy = map[string]bool{}
|
||||
for key, value := range m {
|
||||
mCopy[key] = value
|
||||
}
|
||||
return mCopy
|
||||
}
|
||||
|
@ -20,11 +20,11 @@ func TestJsonToArrayOfStrings(test *testing.T) {
|
||||
var assert = assert.New(test)
|
||||
var result []string
|
||||
utils.JsonToArrayOfStrings("[]", &result)
|
||||
assert.Equal([]string{}, result)
|
||||
assert.ElementsMatch([]string{}, result)
|
||||
utils.JsonToArrayOfStrings("[ \"ganymed\" ]", &result)
|
||||
assert.Equal([]string{"ganymed"}, result)
|
||||
assert.ElementsMatch([]string{"ganymed"}, result)
|
||||
utils.JsonToArrayOfStrings("[ \"ganymed\", \"io\" ]", &result)
|
||||
assert.Equal([]string{"ganymed", "io"}, result)
|
||||
assert.ElementsMatch([]string{"ganymed", "io"}, result)
|
||||
assert.Panics(func() { utils.JsonToArrayOfStrings("[ 178 ]", &result) }, "Should panic if converting not a JSON-encoded array of strings!")
|
||||
assert.Panics(func() { utils.JsonToArrayOfStrings("true", &result) }, "Should panic if converting not a JSON-encoded array of strings!")
|
||||
assert.Panics(func() { utils.JsonToArrayOfStrings("", &result) }, "Should panic if converting not a JSON-encoded array of strings!")
|
||||
@ -73,6 +73,7 @@ func TestSumList(test *testing.T) {
|
||||
func TestSortStrings(test *testing.T) {
|
||||
var assert = assert.New(test)
|
||||
var list = []string{"katze", "Hund", "baby", "Pluto", "Saturn", "Mond"}
|
||||
// NOTE: here use .Equal and not .ElementsMatch, since order important.
|
||||
utils.SortStrings(&list)
|
||||
assert.Equal([]string{"baby", "Hund", "katze", "Mond", "Pluto", "Saturn"}, list)
|
||||
}
|
||||
@ -85,7 +86,7 @@ func TestFilterStrings(test *testing.T) {
|
||||
var assert = assert.New(test)
|
||||
var list = []string{"abram", "aaron", "aardvark", "aarhus", "alaska", "eel", "aal"}
|
||||
var list2 = utils.FilterStrings(&list, func(x string) bool { return strings.HasPrefix(x, "aa") })
|
||||
assert.Equal([]string{"aaron", "aardvark", "aarhus", "aal"}, list2)
|
||||
assert.ElementsMatch([]string{"aaron", "aardvark", "aarhus", "aal"}, list2)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- *
|
||||
@ -97,8 +98,7 @@ func TestUnionStrings2(test *testing.T) {
|
||||
var list1 = []string{"red", "blue", "blue", "green", "blue", "grey", "black", "green"}
|
||||
var list2 = []string{"yellow", "orange", "lila", "red"}
|
||||
var list = utils.UnionStrings2(list1, list2)
|
||||
utils.SortStrings(&list)
|
||||
assert.Equal([]string{"black", "blue", "green", "grey", "lila", "orange", "red", "yellow"}, list)
|
||||
assert.ElementsMatch([]string{"black", "blue", "green", "grey", "lila", "orange", "red", "yellow"}, list)
|
||||
}
|
||||
|
||||
func TestUnionStringsInPlace(test *testing.T) {
|
||||
@ -106,8 +106,7 @@ func TestUnionStringsInPlace(test *testing.T) {
|
||||
var list1 = []string{"red", "blue", "green"}
|
||||
var list2 = []string{"yellow", "red", "blue", "red", "black"}
|
||||
utils.UnionStringsInPlace(&list1, list2)
|
||||
utils.SortStrings(&list1)
|
||||
assert.Equal([]string{"black", "blue", "green", "red", "yellow"}, list1)
|
||||
assert.ElementsMatch([]string{"black", "blue", "green", "red", "yellow"}, list1)
|
||||
}
|
||||
|
||||
func TestUnionStringsList(test *testing.T) {
|
||||
@ -116,6 +115,5 @@ func TestUnionStringsList(test *testing.T) {
|
||||
var lists [][]string
|
||||
lists = [][]string{{"red", "blue", "blue", "green"}, {"yellow", "red", "black"}}
|
||||
list = utils.UnionStringsList(lists)
|
||||
utils.SortStrings(&list)
|
||||
assert.Equal([]string{"black", "blue", "green", "red", "yellow"}, list)
|
||||
assert.ElementsMatch([]string{"black", "blue", "green", "red", "yellow"}, list)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user