func TestCartesianProduce(t *testing.T) { t.Parallel() ranks := set.With([]set.Element{"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"}) suits := set.With([]set.Element{"♠", "♥", "♦", "♣"}) deck := set.CartesianProduct(ranks, suits) if !deck.Contains(set.Tuple{"2", "♠"}) { t.Fatalf("Deck of cards should contain 2 of ♠") } }
func main() { s := set.New() s.Add(1) s.Add(2) s.Add(3) log.Printf("%s", s) ranks := set.With([]set.Element{"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"}) suits := set.With([]set.Element{"♠", "♥", "♦", "♣"}) deck := set.CartesianProduct(ranks, suits) log.Printf("Deck: %s", deck) log.Printf("Number of Cards: %d", deck.Cardinality()) log.Printf("Union of ranks and suits, %v", set.Union(ranks, suits)) log.Printf("Power set of {1, 2, 3}: %v", set.PowerSet(s)) }
func TestConstructors(t *testing.T) { t.Parallel() s := make([]set.Element, 10) for i := 0; i < 10; i++ { s[i] = i } A := set.With(s) B := set.WithElements(s...) for _, v := range s { if !A.Contains(v) { log.Fatal("A should contain %d (created by set.With)", v) } if !B.Contains(v) { log.Fatal("B should contain %d (created with set.WithElements", v) } } }
func main() { s := set.With([]set.Element{"pushups", "reading", "sleep"}) health := relation.New(s) health.AddRelation("sleep", "pushups") health.AddRelation("pushups", "reading") philosophy := relation.New(s) philosophy.AddRelation("reading", "pushups") philosophy.AddRelation("pushups", "sleep") humanity := relation.New(s) humanity.AddRelation("reading", "sleep") humanity.AddRelation("sleep", "pushups") elos := guile.PreferenceProfile{health, philosophy, humanity} r := guile.PairwiseMajority(elos) log.Print(guile.MostPreferred(r)) b := guile.BordaCounting(elos) log.Print(guile.MostPreferred(b)) }