📄 hashtabletestcase.java
字号:
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;
import org.junit.Test;
import junit.framework.TestCase;
public class HashTableTestCase extends TestCase {
public static void main(String[] args) {
junit.textui.TestRunner.run(HashTableTestCase.class);
}
@Test
public void testReadTestFile1_DivisionLinear() {
HashTable table = new HashTable(10, "division", "linear_probing");
assertTrue("Didn't load 19 entries from TestFile1 with division and linear_probing.",table.loadFromFile("TestFile1") == 19);
}
@Test
public void testReadTestFile1_FoldingLinear() {
HashTable table = new HashTable(10, "folding", "linear_probing");
assertTrue("Didn't load 19 entries from TestFile1 with folding and linear_probing.",table.loadFromFile("TestFile1") == 19);
}
@Test
public void testReadTestFile1_MidSquareLinear() {
HashTable table = new HashTable(10, "mid_square", "linear_probing");
assertTrue("Didn't load 19 entries from TestFile1 with mid_square and linear_probing.",table.loadFromFile("TestFile1") == 19);
}
@Test
public void testReadTestFile1_DivisionQuadratic() {
HashTable table = new HashTable(10, "division", "quadratic_probing");
assertTrue("Didn't load 19 entries from TestFile1 with division and quadratic_probing.",table.loadFromFile("TestFile1") == 19);
}
@Test
public void testReadTestFile1_FoldingQuadratic() {
HashTable table = new HashTable(10, "folding", "quadratic_probing");
assertTrue("Didn't load 19 entries from TestFile1 with folding and quadratic_probing.",table.loadFromFile("TestFile1") == 19);
}
@Test
public void testReadTestFile1_MidSquareQuadractic() {
HashTable table = new HashTable(10, "mid_square", "quadratic_probing");
assertTrue("Didn't load 19 entries from TestFile1 with mid_square and quadratic_probing.",table.loadFromFile("TestFile1") == 19);
}
@Test
public void testReadTestFile2_DivisionLinear() {
HashTable table = new HashTable(10, "division", "linear_probing");
assertTrue("Didn't load 99 entries from TestFile2 with division and linear_probing.",table.loadFromFile("TestFile2") == 99);
}
@Test
public void testReadTestFile2_FoldingLinear() {
HashTable table = new HashTable(10, "folding", "linear_probing");
assertTrue("Didn't load 99 entries from TestFile2 with folding and linear_probing.",table.loadFromFile("TestFile2") == 99);
}
@Test
public void testReadTestFile2_MidSquareLinear() {
HashTable table = new HashTable(10, "mid_square", "linear_probing");
assertTrue("Didn't load 99 entries from TestFile2 with mid_square and linear_probing.",table.loadFromFile("TestFile2") == 99);
}
@Test
public void testReadTestFile2_DivisionQuadratic() {
HashTable table = new HashTable(10, "division", "quadratic_probing");
assertTrue("Didn't load 99 entries from TestFile2 with division and quadratic_probing.",table.loadFromFile("TestFile2") == 99);
}
@Test
public void testReadTestFile2_FoldingQuadratic() {
HashTable table = new HashTable(10, "folding", "quadratic_probing");
assertTrue("Didn't load 99 entries from TestFile2 with folding and quadratic_probing.",table.loadFromFile("TestFile2") == 99);
}
@Test
public void testReadTestFile2_MidSquareQuadractic() {
HashTable table = new HashTable(10, "mid_square", "quadratic_probing");
assertTrue("Didn't load 99 entries from TestFile2 with mid_square and quadratic_probing.",table.loadFromFile("TestFile2") == 99);
}
@Test
public void testInsert_DivisionLinear() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "division", "linear_probing");
assertNotNull(table.insert(testEntry1));
}
@Test
public void testInsert_FoldingLinear() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "folding", "linear_probing");
assertNotNull(table.insert(testEntry1));
}
@Test
public void testInsert_MidSquareLinear() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "mid_square", "linear_probing");
assertNotNull(table.insert(testEntry1));
}
@Test
public void testInsert_DivisionQuadratic() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "division", "quadratic_probing");
assertNotNull(table.insert(testEntry1));
}
@Test
public void testInsert_FoldingQuadratic() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "folding", "quadratic_probing");
assertNotNull(table.insert(testEntry1));
}
@Test
public void testInsert_MidSquareQuadratic() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "mid_square", "quadratic_probing");
assertNotNull(table.insert(testEntry1));
}
@Test
public void testFind_DivisionLinear() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "division", "linear_probing");
assertNotNull(table.insert(testEntry1));
Entry foundEntry = table.find(testEntry1.getKey());
assertNotNull("Didn't find Entry " + testEntry1.getKey() + ".", foundEntry);
assertTrue("Inserted Entry " + testEntry1.getKey() + " and found Entry " + foundEntry.getKey() + " are not the same.", foundEntry == testEntry1);
}
@Test
public void testFind_FoldingLinear() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "folding", "linear_probing");
assertNotNull(table.insert(testEntry1));
Entry foundEntry = table.find(testEntry1.getKey());
assertNotNull("Didn't find Entry " + testEntry1.getKey() + ".", foundEntry);
assertTrue("Inserted Entry " + testEntry1.getKey() + " and found Entry " + foundEntry.getKey() + " are not the same.", foundEntry == testEntry1);
}
@Test
public void testFind_MidSquareLinear() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "mid_square", "linear_probing");
assertNotNull(table.insert(testEntry1));
Entry foundEntry = table.find(testEntry1.getKey());
assertNotNull("Didn't find Entry " + testEntry1.getKey() + ".", foundEntry);
assertTrue("Inserted Entry " + testEntry1.getKey() + " and found Entry " + foundEntry.getKey() + " are not the same.", foundEntry == testEntry1);
}
@Test
public void testFind_DivisionQuadratic() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "division", "quadratic_probing");
assertNotNull(table.insert(testEntry1));
Entry foundEntry = table.find(testEntry1.getKey());
assertNotNull("Didn't find Entry " + testEntry1.getKey() + ".", foundEntry);
assertTrue("Inserted Entry " + testEntry1.getKey() + " and found Entry " + foundEntry.getKey() + " are not the same.", foundEntry == testEntry1);
}
@Test
public void testFind_FoldingQuadratic() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "folding", "quadratic_probing");
assertNotNull(table.insert(testEntry1));
Entry foundEntry = table.find(testEntry1.getKey());
assertNotNull("Didn't find Entry " + testEntry1.getKey() + ".", foundEntry);
assertTrue("Inserted Entry " + testEntry1.getKey() + " and found Entry " + foundEntry.getKey() + " are not the same.", foundEntry == testEntry1);
}
@Test
public void testFind_MidSquareQuadratic() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "mid_square", "quadratic_probing");
assertNotNull(table.insert(testEntry1));
Entry foundEntry = table.find(testEntry1.getKey());
assertNotNull("Didn't find Entry " + testEntry1.getKey() + ".", foundEntry);
assertTrue("Inserted Entry " + testEntry1.getKey() + " and found Entry " + foundEntry.getKey() + " are not the same.", foundEntry == testEntry1);
}
@Test
public void testDelete_DivisionLinear() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "division", "linear_probing");
assertNotNull(table.insert(testEntry1));
assertNotNull(table.delete(testEntry1.getKey()));
assertNull(table.find(testEntry1.getKey()));
}
@Test
public void testDelete_FoldingLinear() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "folding", "linear_probing");
assertNotNull(table.insert(testEntry1));
assertNotNull(table.delete(testEntry1.getKey()));
assertNull(table.find(testEntry1.getKey()));
}
@Test
public void testDelete_MidSquareLinear() {
Entry testEntry1 = new Entry();
testEntry1.setKey("ABCDELDXS");
testEntry1.setData("OK");
HashTable table = new HashTable(10, "mid_square", "linear_probing");
assertNotNull(table.insert(testEntry1));
assertNotNull(table.delete(testEntry1.getKey()));
assertNull(table.find(testEntry1.getKey()));
}
@Test
public void testDelete_DivisionQuadratic() {
Entry testEntry1 = new Entry();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -