Skip to content

Commit 579b185

Browse files
committed
TEST: Add test case
1 parent 0972054 commit 579b185

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from lpynn.perceptron import init_perceptron, print_perceptron, normalize_input_vectors, Perceptron, train_dataset
2+
from lptypes import i32, f64
3+
4+
def main0():
5+
p: Perceptron = Perceptron(0, [0.0], 0.0, 0, 0.0, 0.0, 0)
6+
init_perceptron(p, 2, 0.05, 10000, 90.0)
7+
print_perceptron(p)
8+
print("=================================")
9+
10+
input_vectors: list[list[f64]] = [[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, 1.0]]
11+
outputs: list[i32] = [1, 1, 1, -1]
12+
13+
normalize_input_vectors(input_vectors)
14+
train_dataset(p, input_vectors, outputs)
15+
print_perceptron(p)
16+
print("=================================")
17+
18+
assert p.cur_accuracy > 50.0
19+
assert p.epochs_cnt > 1
20+
21+
def main1():
22+
p: Perceptron = Perceptron(0, [0.0], 0.0, 0, 0.0, 0.0, 0)
23+
init_perceptron(p, 2, 0.05, 10000, 90.0)
24+
print_perceptron(p)
25+
print("=================================")
26+
27+
input_vectors: list[list[f64]] = [[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, 1.0], [1.5, 1.0]]
28+
outputs: list[i32] = [1, 1, -1, 1, -1]
29+
30+
normalize_input_vectors(input_vectors)
31+
train_dataset(p, input_vectors, outputs)
32+
print_perceptron(p)
33+
print("=================================")
34+
35+
assert p.cur_accuracy > 50.0
36+
assert p.epochs_cnt > 1
37+
38+
main0()
39+
main1()

0 commit comments

Comments
 (0)