aboutsummaryrefslogtreecommitdiffstats
path: root/test/eu/equalparts/cardbase/decks/StatisticsTest.java
blob: 6210f898991f953236710864b39e72e9d4123fd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package eu.equalparts.cardbase.decks;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

import eu.equalparts.cardbase.decks.StandaloneDeck;
import eu.equalparts.cardbase.decks.Statistics;

public class StatisticsTest {

	private static StandaloneDeck uut;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		ObjectMapper mapper = new ObjectMapper();
		uut = mapper.readValue(StatisticsTest.class.getResourceAsStream("deck.cbd"), StandaloneDeck.class);
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void test_totalLandCountIsComputedCorrectly() throws Exception {
		int count = Statistics.count(uut, "Land");
		
		assertEquals(23, count);
	}
	
	@Test
	public void test_basicLandCountIsComputedCorrectly() throws Exception {
		int count = Statistics.count(uut, "Basic Land");
		
		assertEquals(20, count);
	}
	
	@Test
	public void test_cardCountIsComputedCorrectly() throws Exception {
		int count = Statistics.count(uut);
		
		assertEquals(60, count);
	}
	
	@Test
	public void test_landPercentageIsComputedCorrectly() throws Exception {
		double percentage = Statistics.calculatePercentage(uut, "Land");
		
		assertTrue("Land percentage should be " + (23.0 / 60.0) + ", is " + percentage, percentage == (23.0 / 60.0));
	}
	
	@Test
	public void test_creaturePercentageIsComputedCorrectly() throws Exception {
		double percentage = Statistics.calculatePercentage(uut, "Creature");
		
		assertTrue("Creature percentage should be " + (24.0 / 60.0) + ", is " + percentage, percentage == (24.0 / 60.0));
	}
	
	@Test
	public void test_creatureCountIsComputedCorrectly() throws Exception {
		int count = Statistics.count(uut, "Creature");
		
		assertEquals(24, count);
	}
	
	@Test
	public void test_sorceryCountIsComputedCorrectly() throws Exception {
		int count = Statistics.count(uut, "Sorcery");
		
		assertEquals(1, count);
	}
	
	@Test
	public void test_instantCountIsComputedCorrectly() throws Exception {
		int count = Statistics.count(uut, "Instant");
		
		assertEquals(6, count);
	}
	
	@Test
	public void test_planeswalkerCountIsComputedCorrectly() throws Exception {
		int count = Statistics.count(uut, "Planeswalker");
		
		assertEquals(0, count);
	}
	
	@Test
	public void test_elfCountIsComputedCorrectly() throws Exception {
		int count = Statistics.count(uut, "Elf");
		
		assertEquals(2, count);
	}
	
	@Test
	public void test_overallCostDistributionIsComputedCorrectly() throws Exception {
		int[] actualCosts = Statistics.computeDistribution(uut);
		int[] expectedCosts = {0, 8, 11, 3, 4, 7, 4};
		
		assertEquals("Array lengths do not match.", expectedCosts.length, actualCosts.length);
		for (int i = 0; i < expectedCosts.length; i++) {
			assertEquals("CMC: " + i, expectedCosts[i], actualCosts[i]);
		}
	}
	
	@Test
	public void test_creatureCostDistributionIsComputedCorrectly() throws Exception {
		int[] actualCosts = Statistics.computeDistribution(uut, "Creature");
		int[] expectedCosts = {0, 3, 6, 2, 2, 7, 4};
		
		assertEquals("Array lengths do not match.", expectedCosts.length, actualCosts.length);
		for (int i = 0; i < expectedCosts.length; i++) {
			assertEquals("CMC: " + i, expectedCosts[i], actualCosts[i]);
		}
	}
	
	@Test
	public void test_instantCostDistributionIsComputedCorrectly() throws Exception {
		int[] actualCosts = Statistics.computeDistribution(uut, "Instant");
		int[] expectedCosts = {0, 2, 4};
		
		assertEquals("Array lengths do not match.", expectedCosts.length, actualCosts.length);
		for (int i = 0; i < expectedCosts.length; i++) {
			assertEquals("CMC: " + i, expectedCosts[i], actualCosts[i]);
		}
	}
	
	@Test
	public void test_planeswalkerCostDistributionIsComputedCorrectly() throws Exception {
		int[] actualCosts = Statistics.computeDistribution(uut, "Planeswalker");
		int[] expectedCosts = {};
		
		assertEquals("Array lengths do not match.", expectedCosts.length, actualCosts.length);
		for (int i = 0; i < expectedCosts.length; i++) {
			assertEquals("CMC: " + i, expectedCosts[i], actualCosts[i]);
		}
	}
	
}