I'm working on a self-coded HashTable. And now I stuck in testing the damn thing. This is my test-work so far:
//Put Test
Random r = new Random();
for (int i = 0; i < 1000; i++) {
int k = r.nextInt(256);
dummy[i] = k;
hash.put(i, k);
}
assertEquals(1000, hash.size());
//Key Value Test
for (int i = 0; i < 1000; i++) {
assertEquals(dummy[i], hash.get(i));
}
//Key Value Test 2
for (int i = 0; i < 1000; i++) {
int k = r.nextInt(256);
if (i % 2 == 0) {
dummy[i] = k;
hash.put(i, k);
}
}
for (int i = 0; i < 1000; i++) {
if (i % 2 != 0) {
assertEquals(null, hash.get(i));
}
if (i % 2 == 0) {
assertEquals(dummy[i], hash.get(i));
}
}
//Key Value Test 3
for (int i = 0; i < 1000; i++) {
if (i % 2 == 0) {
hash.put(i, null);
}
else {
hash.put(i, 1);
}
}
for (int i = 0; i < 1000; i++) {
if (i % 2 != 0) {
assertEquals(1, hash.get(i));
}
if (i % 2 == 0) {
assertEquals(null, hash.get(i));
}
//Remove Test
for (int i = 0; i < 1000; i++) {
hash.remove(i);
}
assertEquals(0, hash.size());
Any Ideas how I can test my HashTable better ? Or cleverer ? All my test are functional tests. Maybe a big O-Notation test, but how ?
Aucun commentaire:
Enregistrer un commentaire