Exemplo n.º 1
0
//Testing scoring after 1 trick
func TestOne(test *testing.T) {
	p2Expect := 15
	otherExpect := 0
	p0 := player.NewPlayer(0)
	p1 := player.NewPlayer(1)
	p2 := player.NewPlayer(2)
	p3 := player.NewPlayer(3)
	players := []*player.Player{p0, p1, p2, p3}
	t := table.NewTable(players)
	t.SetFirstPlayed(1)
	t.PlayCard(card.NewCard(3, card.Heart), 1)
	t.PlayCard(card.NewCard(7, card.Heart), 2)
	t.PlayCard(card.NewCard(12, card.Spade), 3)
	t.PlayCard(card.NewCard(4, card.Diamond), 0)
	t.SendTrick()
	t.EndRound()
	score := p0.GetScore()
	if score != otherExpect {
		test.Errorf("Expected %d, got %d", otherExpect, score)
	}
	score = p1.GetScore()
	if score != otherExpect {
		test.Errorf("Expected %d, got %d", otherExpect, score)
	}
	score = p2.GetScore()
	if score != p2Expect {
		test.Errorf("Expected %d, got %d", p2Expect, score)
	}
	score = p3.GetScore()
	if score != otherExpect {
		test.Errorf("Expected %d, got %d", otherExpect, score)
	}
}
Exemplo n.º 2
0
func (t *Table) GenerateCards() {
	t.allCards = make([]*card.Card, 0)
	for i := 0; i < 13; i++ {
		t.allCards = append(t.allCards, card.NewCard(i+2, card.Club))
		t.allCards = append(t.allCards, card.NewCard(i+2, card.Diamond))
		t.allCards = append(t.allCards, card.NewCard(i+2, card.Spade))
		t.allCards = append(t.allCards, card.NewCard(i+2, card.Heart))
	}
}
Exemplo n.º 3
0
//Testing win condition
func TestTwelve(test *testing.T) {
	p0 := player.NewPlayer(0)
	players := []*player.Player{p0}
	t := table.NewTable(players)
	t.SetFirstPlayed(0)
	t.PlayCard(card.NewCard(12, card.Spade), 0)
	t.SendTrick()
	t.PlayCard(card.NewCard(12, card.Spade), 0)
	t.SendTrick()
	t.PlayCard(card.NewCard(12, card.Spade), 0)
	t.SendTrick()
	winner := t.EndRound()
	expect := -1
	if winner != expect {
		test.Errorf("Expected %d, got %d", expect, winner)
	}
	t.NewRound()
	t.PlayCard(card.NewCard(12, card.Spade), 0)
	t.SendTrick()
	t.PlayCard(card.NewCard(12, card.Spade), 0)
	t.SendTrick()
	t.PlayCard(card.NewCard(12, card.Spade), 0)
	t.SendTrick()
	t.PlayCard(card.NewCard(12, card.Spade), 0)
	t.SendTrick()
	t.PlayCard(card.NewCard(12, card.Spade), 0)
	t.SendTrick()
	t.PlayCard(card.NewCard(12, card.Spade), 0)
	t.SendTrick()
	winner = t.EndRound()
	expect = 0
	if winner != expect {
		test.Errorf("Expected %d, got %d", expect, winner)
	}
}
Exemplo n.º 4
0
//Testing playing a card-- ValidPlay() testing 2 of Clubs rule
func TestEight(test *testing.T) {
	p0 := player.NewPlayer(0)
	players := []*player.Player{p0}
	t := table.NewTable(players)
	t.SetFirstPlayed(0)
	if t.ValidPlay(card.NewCard(8, card.Club), 0) == true {
		test.Errorf("Expected invalid play for starting round with card other than 2 of Clubs")
	} else if t.ValidPlay(card.NewCard(2, card.Club), 0) == false {
		test.Errorf("Expected valid play for starting round with 2 of Clubs")
	}
}
Exemplo n.º 5
0
//Testing playing a card-- HasSuit()
func TestSix(test *testing.T) {
	p := player.NewPlayer(0)
	p.AddToHand(card.NewCard(6, card.Diamond))
	p.AddToHand(card.NewCard(4, card.Spade))
	if p.HasSuit(card.Diamond) == false || p.HasSuit(card.Spade) == false {
		test.Errorf("False negative")
	}
	if p.HasSuit(card.Club) == true || p.HasSuit(card.Heart) == true {
		test.Errorf("False positive")
	}
}
Exemplo n.º 6
0
//Testing playing a card-- ValidPlay() testing first round points rule
func TestNine(test *testing.T) {
	p0 := player.NewPlayer(0)
	p1 := player.NewPlayer(1)
	p1.AddToHand(card.NewCard(12, card.Spade))
	p1.AddToHand(card.NewCard(3, card.Diamond))
	players := []*player.Player{p0, p1}
	t := table.NewTable(players)
	t.SetFirstPlayed(0)
	t.PlayCard(card.NewCard(2, card.Club), 0)
	if t.ValidPlay(card.NewCard(12, card.Spade), 1) == true {
		test.Errorf("Expected invalid play for points on the first round")
	}
}
Exemplo n.º 7
0
//Testing playing a card-- HasAllPoints()
func TestSeven(test *testing.T) {
	p1 := player.NewPlayer(0)
	p2 := player.NewPlayer(1)
	p1.AddToHand(card.NewCard(6, card.Heart))
	p1.AddToHand(card.NewCard(12, card.Spade))
	p2.AddToHand(card.NewCard(2, card.Diamond))
	p2.AddToHand(card.NewCard(5, card.Heart))
	if p1.HasAllPoints() == false {
		test.Errorf("False negative")
	}
	if p2.HasAllPoints() == true {
		test.Errorf("False positive")
	}
}
Exemplo n.º 8
0
//Testing playing a card-- ValidPlay() testing following suit rule
func TestEleven(test *testing.T) {
	p0 := player.NewPlayer(0)
	p1 := player.NewPlayer(1)
	p0.AddToHand(card.NewCard(2, card.Club))
	p1.AddToHand(card.NewCard(3, card.Diamond))
	players := []*player.Player{p0, p1}
	t := table.NewTable(players)
	t.SetFirstPlayed(0)
	t.PlayCard(card.NewCard(2, card.Club), 0)
	if t.ValidPlay(card.NewCard(3, card.Diamond), 1) == false {
		test.Errorf("Expected valid play for not following suit when player doesn't have suit")
	}
	p1.AddToHand(card.NewCard(5, card.Club))
	if t.ValidPlay(card.NewCard(5, card.Club), 1) == false {
		test.Errorf("Expected valid play for following suit")
	}
	if t.ValidPlay(card.NewCard(3, card.Diamond), 1) == true {
		test.Errorf("Expected invalid play for not following suit when player has suit")
	}
}
Exemplo n.º 9
0
//Testing playing a card-- ValidPlay() testing breaking Hearts rule
func TestTen(test *testing.T) {
	p0 := player.NewPlayer(0)
	p1 := player.NewPlayer(1)
	p0.AddToHand(card.NewCard(5, card.Heart))
	p1.AddToHand(card.NewCard(2, card.Heart))
	p1.AddToHand(card.NewCard(3, card.Diamond))
	players := []*player.Player{p0, p1}
	t := table.NewTable(players)
	t.SetFirstPlayed(0)
	t.PlayCard(card.NewCard(2, card.Club), 0)
	t.PlayCard(card.NewCard(3, card.Club), 1)
	t.SendTrick()
	t.SetFirstPlayed(0)
	if t.ValidPlay(card.NewCard(5, card.Heart), 0) == false {
		test.Errorf("Expected valid play for opener rightfully breaking Hearts")
	}
	t.SetFirstPlayed(1)
	if t.ValidPlay(card.NewCard(2, card.Heart), 1) == true {
		test.Errorf("Expected invalid play for opener wrongfully breaking Hearts")
	}
	t.PlayCard(card.NewCard(3, card.Diamond), 1)
	if t.ValidPlay(card.NewCard(5, card.Heart), 0) == false {
		test.Errorf("Expected valid play for follower rightfully breaking Hearts")
	}
	p0.AddToHand(card.NewCard(7, card.Diamond))
	if t.ValidPlay(card.NewCard(5, card.Heart), 0) == true {
		test.Errorf("Expected invalid play for follower wrongfully breaking Hearts")
	}
}