Esempio n. 1
0
func TestSetUnion(t *testing.T) {
	t.Parallel()

	A := set.WithElements(1, 2, 3)
	B := set.WithElements(4, 5, 6)
	U := set.Union(A, B)

	for i := 1; i < 7; i++ {
		if !U.Contains(i) {
			t.Fatalf("Union of %s and %s should contain %d", A, B, i)
		}
	}

	if U.Cardinality() != 6 {
		t.Fatalf("Expected cardinality of union of %s and %s to be 6", A, B)
	}

	U.Remove(1)
	U.Remove(6)

	if !A.Contains(1) || !B.Contains(6) {
		t.Fatalf("Modifying the union set should not change the original set")
	}

}
Esempio n. 2
0
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))
}
Esempio n. 3
0
// IndependentEvents determines whether A and B are independent
// under the distribution d.
//
// Equivalently: P(A, B) = P(A)P(B)
func IndependentEvents(d Distribution, A, B Event) bool {
	return equiv(float64(ProbabilityOf(d, set.Union(A, B))), float64(ProbabilityOf(d, A)*ProbabilityOf(d, B)))
}