1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.collect;
18
19 import com.google.common.annotations.GwtCompatible;
20
21
22
23
24
25
26 @GwtCompatible(emulated = true)
27 public class HashBasedTableTest extends AbstractTableTest {
28
29 @Override protected Table<String, Integer, Character> create(
30 Object... data) {
31 Table<String, Integer, Character> table = HashBasedTable.create();
32 table.put("foo", 4, 'a');
33 table.put("cat", 1, 'b');
34 table.clear();
35 populate(table, data);
36 return table;
37 }
38
39 public void testCreateWithValidSizes() {
40 Table<String, Integer, Character> table1 = HashBasedTable.create(100, 20);
41 table1.put("foo", 1, 'a');
42 assertEquals((Character) 'a', table1.get("foo", 1));
43
44 Table<String, Integer, Character> table2 = HashBasedTable.create(100, 0);
45 table2.put("foo", 1, 'a');
46 assertEquals((Character) 'a', table2.get("foo", 1));
47
48 Table<String, Integer, Character> table3 = HashBasedTable.create(0, 20);
49 table3.put("foo", 1, 'a');
50 assertEquals((Character) 'a', table3.get("foo", 1));
51
52 Table<String, Integer, Character> table4 = HashBasedTable.create(0, 0);
53 table4.put("foo", 1, 'a');
54 assertEquals((Character) 'a', table4.get("foo", 1));
55 }
56
57 public void testCreateWithInvalidSizes() {
58 try {
59 HashBasedTable.create(100, -5);
60 fail();
61 } catch (IllegalArgumentException expected) {}
62
63 try {
64 HashBasedTable.create(-5, 20);
65 fail();
66 } catch (IllegalArgumentException expected) {}
67 }
68
69 public void testCreateCopy() {
70 Table<String, Integer, Character> original
71 = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
72 Table<String, Integer, Character> copy = HashBasedTable.create(original);
73 assertEquals(original, copy);
74 assertEquals((Character) 'a', copy.get("foo", 1));
75 }
76 }
77