Yioop_V9.5_Source_Code_Documentation

HashTableTest extends UnitTest
in package

Used to test that the HashTable class properly stores key value pairs, handles insert, deletes, collisions okay. It should also detect when table is full

Tags
author

Chris Pollett

Table of Contents

case_name  = "TestCase"
The suffix that all TestCase methods need to have to be called by run()
$current_method  : string
Contains the value of the next test case to be run can be used by setUp
$test_case_results  : array<string|int, mixed>
Used to store the results for each test sub case
$test_objects  : array<string|int, mixed>
Used to hold objects to be used in tests
__construct()  : mixed
Constructor should be overridden to do any set up that occurs before and test cases
assertEqual()  : mixed
Checks that $x and $y are the same, the result of the test is added to $this->test_case_results
assertFalse()  : mixed
Checks that $x can coerced to false, the result of the test is added to $this->test_case_results
assertNotEqual()  : mixed
Checks that $x and $y are not the same, the result of the test is added to $this->test_case_results
assertTrue()  : mixed
Checks that $x can coerced to true, the result of the test is added to $this->test_case_results
completeFillTestCase()  : mixed
Completety fill table. Next insert should fail. Then delete all the items. Then check that we can't find any of them
insertDeleteLookupTestCase()  : mixed
Checks insert an item, delete that item, then look it up. Make sure we don't find it after deletion.
insertLookupTestCase()  : mixed
Check if for the big hash table we insert something then later look it up, that we in fact find it. Moreover, the value we associated with the insert key is as expected
reinsertCollisionAndIndexTestCase()  : mixed
First check that inserting an item twice does not change its index in the table. Then inserts an item which should hash to the same value. So there is a collision which is resolved by linear offset. Check lookup of new item succeeds.Then delete first insert, check lookup of second insert still works. Check delete of second item, reinsert of first item and lookup. Index should change
run()  : array<string|int, mixed>
Execute each of the test cases of this unit test and return the results
setUp()  : mixed
We'll use two different tables one more representative of how the table is going to be used by the web_queue_bundle, the other small enough that we can manually figure out what the result should be
tearDown()  : mixed
Since a HashTable is a PersistentStructure it periodically saves itself to a file. To clean up we delete the files that might be created
timingTestCase()  : mixed
Test how fast insertion and deletions can be done

Constants

case_name

The suffix that all TestCase methods need to have to be called by run()

public mixed case_name = "TestCase"

Properties

$current_method

Contains the value of the next test case to be run can be used by setUp

public string $current_method

$test_case_results

Used to store the results for each test sub case

public array<string|int, mixed> $test_case_results

$test_objects

Used to hold objects to be used in tests

public array<string|int, mixed> $test_objects

Methods

__construct()

Constructor should be overridden to do any set up that occurs before and test cases

public __construct() : mixed
Return values
mixed

assertEqual()

Checks that $x and $y are the same, the result of the test is added to $this->test_case_results

public assertEqual(mixed $x, mixed $y[, string $description = "" ]) : mixed
Parameters
$x : mixed

a first item to compare

$y : mixed

a second item to compare

$description : string = ""

information about this test subcase

Return values
mixed

assertFalse()

Checks that $x can coerced to false, the result of the test is added to $this->test_case_results

public assertFalse(mixed $x[, string $description = "" ]) : mixed
Parameters
$x : mixed

item to check

$description : string = ""

information about this test subcase

Return values
mixed

assertNotEqual()

Checks that $x and $y are not the same, the result of the test is added to $this->test_case_results

public assertNotEqual(mixed $x, mixed $y[, string $description = "" ]) : mixed
Parameters
$x : mixed

a first item to compare

$y : mixed

a second item to compare

$description : string = ""

information about this test subcase

Return values
mixed

assertTrue()

Checks that $x can coerced to true, the result of the test is added to $this->test_case_results

public assertTrue(mixed $x[, string $description = "" ]) : mixed
Parameters
$x : mixed

item to check

$description : string = ""

information about this test subcase

Return values
mixed

completeFillTestCase()

Completety fill table. Next insert should fail. Then delete all the items. Then check that we can't find any of them

public completeFillTestCase() : mixed
Return values
mixed

insertDeleteLookupTestCase()

Checks insert an item, delete that item, then look it up. Make sure we don't find it after deletion.

public insertDeleteLookupTestCase() : mixed
Return values
mixed

insertLookupTestCase()

Check if for the big hash table we insert something then later look it up, that we in fact find it. Moreover, the value we associated with the insert key is as expected

public insertLookupTestCase() : mixed
Return values
mixed

reinsertCollisionAndIndexTestCase()

First check that inserting an item twice does not change its index in the table. Then inserts an item which should hash to the same value. So there is a collision which is resolved by linear offset. Check lookup of new item succeeds.Then delete first insert, check lookup of second insert still works. Check delete of second item, reinsert of first item and lookup. Index should change

public reinsertCollisionAndIndexTestCase() : mixed
Return values
mixed

run()

Execute each of the test cases of this unit test and return the results

public run([string $method = null ]) : array<string|int, mixed>
Parameters
$method : string = null

if not null then the method to run, else run all methods

Return values
array<string|int, mixed>

test case results

setUp()

We'll use two different tables one more representative of how the table is going to be used by the web_queue_bundle, the other small enough that we can manually figure out what the result should be

public setUp() : mixed
Return values
mixed

tearDown()

Since a HashTable is a PersistentStructure it periodically saves itself to a file. To clean up we delete the files that might be created

public tearDown() : mixed
Return values
mixed

timingTestCase()

Test how fast insertion and deletions can be done

public timingTestCase() : mixed
Return values
mixed

        

Search results