func TestFirstElement(t *testing.T) { empty, one, _, _ := clause.ConstructTestClauses() //case0 -- emptyClauseSet cs := ClauseSet{} got, err := cs.FirstElement() want := clause.Clause{} if !clause.Equals(got, want) || err == nil { t.Errorf("%q.FirstElement() == %q, want %q (error: %q)", cs, got, want, err) } //case1 -- one thing cs = ClauseSet{} cs.Append(empty) got, err = cs.FirstElement() want = clause.Clause{} if !clause.Equals(got, want) || err != nil { t.Errorf("%q.FirstElement() == %q, want %q (error: %q)", cs, got, want, err) } //case2 -- two things cs = ClauseSet{} cs.Append(one) cs.Append(empty) got, err = cs.FirstElement() want = clause.Clause{} if !clause.Equals(got, want) || err != nil { t.Errorf("%q.FirstElement() == %q, want %q (error: %q)", cs, got, want, err) } }
//Append adds a clause to the ClauseSet func (c *ClauseSet) Append(a clause.Clause) { for _, b := range c.clauses { if clause.Equals(a, b) { return } } c.clauses = append(c.clauses, a) sort.Sort(c.clauses) }
//Equals returns the equality of two ClauseSets func Equals(a, b ClauseSet) bool { if a.Len() != b.Len() { return false } for i := 0; i < a.Len(); i++ { if !clause.Equals(a.clauses[i], b.clauses[i]) { return false } } return true }