Tests
Tests
class Tests:
def __init__(self):
"""
Initializes modules required for the tests
"""
self.layer = Layer(2, 3)
self.network = Network([2, 3, 2])
def test_layer_output_calculation(self):
"""
Test for the calculate outputs function for the individual layers.
Currently configured for Sigmoid Squishification activation function
"""
self.layer.weights = [
[1.0, 0.5],
[0.75, 1.5],
[0.0, 2.0]
]
outputs = self.layer.calculate_outputs(inputs)
for i in range(len(outputs)):
outputs[i] = round(outputs[i], 5)
def test_network_feed_inputs(self):
"""
Test for feeding the inputs to the network.
"""
self.network.feed_inputs(inputs)
def test_network_run_calculations(self):
"""
Test for the entire neural network. Currently configured for sigmoid
squishification activation function
"""
self.network.layers[0].weights = [
[1.0, 0.5],
[0.75, 1.5],
[0.0, 2.0]
]
self.network.layers[1].weights = [
[0.5, 1.0, 2.5],
[0.0, 0.5, -1.5],
]
# Defining precomputed, correct values for what the function being tested
should produce
self.network.feed_inputs(inputs)
outputs = self.network.run_calculations()
for i in range(len(outputs)):
outputs[i] = round(outputs[i], 5)
# Checking if the output of the function in question, and precomputed,
correct outputs match
def test_activation_function(self):
"""
Test for the activation function. Currently configured to test sigmoid
squishification
"""
# Defining the various inputs that the activation function will be tested
for
for i in range(len(x)):
x[i] = round(self.layer.activation_function(x[i]), 5)
"""
Generic function for printing the test results of a test. Parameters in
order:
1. name : Specifies the name of the test, will be printed at the
top
2. result : The result that the functionality being tested gave
3. expected_result : The result that the functionality being tested should
give for the test to pass
If the result equals the expected result this function will print that it
passed, otherwise,
this function will print that the test failed failed.
"""
print("---------------------------------------")
if (result == expected_result):
print(colored(f"TEST : {name} : PASSED", "cyan", attrs=['bold']))
else:
print(colored(f"TEST : {name} : FAILED", "red", attrs=['bold']))
print("---------------------------------------")
print(F"EXPECTED OUTPUT : {expected_result}")
print(f"GIVEN OUTPUT : {result}")
print("---------------------------------------\n")