Selaa lähdekoodia

Add a matrix creation test

jonathanvdc 8 vuotta sitten
vanhempi
commit
c0d63ff8af

+ 7 - 0
performance/code/create_matrix.alc

@@ -0,0 +1,7 @@
+include "primitives.alh"
+
+Element function create_random_matrix(n : Integer)
+
+Void function test_main():
+	create_random_matrix(input())
+	return!

+ 23 - 0
performance/code/matrix.alc

@@ -0,0 +1,23 @@
+include "primitives.alh"
+include "random.alh"
+
+Element function create_random_matrix(n : Integer):
+	Element m
+	Integer i
+	Integer j
+	Element t
+
+	// Construct the matrix first, with as many rows as there are variables
+	// Number of columns is 1 higher
+	i = 0
+	m = create_node()
+	while (i < n):
+		j = 0
+		t = create_node()
+		while (j < (n + 1)):
+			list_append(t, random())
+			j = j + 1
+		list_append(m, t)
+		i = i + 1
+
+	return m!

+ 19 - 0
performance/test_create_matrix.py

@@ -0,0 +1,19 @@
+import unittest
+import utils
+
+
+class TestCreateMatrix(unittest.TestCase):
+    def test_po_create_matrix(self):
+        self.create_matrix("PO")
+
+    def test_co_create_matrix(self):
+        self.create_matrix("CO")
+
+    def create_matrix(self, mode):
+        print(
+            utils.run_file_single_output(
+                ["test_harness.alc", "matrix.alc",
+                 "create_matrix.alc", "primitives.alc",
+                 "random.alc"],
+                [100, 0],
+                mode))