summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjofret2008-05-30 09:27:09 +0000
committerjofret2008-05-30 09:27:09 +0000
commit867b78da98f4369816c70a5f00d31d4e4016ba0a (patch)
treeefdc6dbf9ada0c6b6bd75be3d8de2559e1e39940 /src
parent0b4335bab178e4e47e9a2b67d32a30d07f3c6b50 (diff)
downloadscilab2c-867b78da98f4369816c70a5f00d31d4e4016ba0a.tar.gz
scilab2c-867b78da98f4369816c70a5f00d31d4e4016ba0a.tar.bz2
scilab2c-867b78da98f4369816c70a5f00d31d4e4016ba0a.zip
* adding random tests for Addition and Subtraction
Diffstat (limited to 'src')
-rw-r--r--src/matrixOperations/testMatrixAddition.c128
-rw-r--r--src/matrixOperations/testMatrixSubtraction.c128
2 files changed, 256 insertions, 0 deletions
diff --git a/src/matrixOperations/testMatrixAddition.c b/src/matrixOperations/testMatrixAddition.c
new file mode 100644
index 00000000..ceb922b9
--- /dev/null
+++ b/src/matrixOperations/testMatrixAddition.c
@@ -0,0 +1,128 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008-2008 - INRIA - Bruno JOFRET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <math.h>
+#include "matrixAddition.h"
+
+#define SIZE 10000
+
+/* #define LOCAL_DEBUG */
+
+static void zaddmaTest(void) {
+ doubleComplex M1[SIZE];
+ doubleComplex M2[SIZE];
+ doubleComplex M1_and_M2[SIZE];
+
+ int i = 0;
+
+ srand(1);
+ for (i = 0; i < SIZE; ++i) {
+ M1[i] = DoubleComplex((double) rand(), (double) rand());
+ M2[i] = DoubleComplex((double) rand(), (double) rand());
+ }
+ zaddma(M1, SIZE, M2, SIZE, M1_and_M2);
+ for (i = 0; i < SIZE; ++i) {
+#ifdef LOCAL_DEBUG
+ printf("M1_and_M2 = %e + %e i\n", zreals(M1_and_M2[i]), zimags(M1_and_M2[i]));
+#endif
+ assert(zreals(M1_and_M2[i]) - (zreals(M1[i]) + zreals(M2[i])) == 0);
+ assert(zimags(M1_and_M2[i]) - (zimags(M1[i]) + zimags(M2[i])) == 0);
+ }
+}
+
+static void caddmaTest(void) {
+ floatComplex M1[SIZE];
+ floatComplex M2[SIZE];
+ floatComplex M1_and_M2[SIZE];
+
+ int i = 0;
+
+ srand(1);
+ for (i = 0; i < SIZE; ++i) {
+ M1[i] = FloatComplex((float) rand(), (float) rand());
+ M2[i] = FloatComplex((float) rand(), (float) rand());
+ }
+ caddma(M1, SIZE, M2, SIZE, M1_and_M2);
+ for (i = 0; i < SIZE; ++i) {
+#ifdef LOCAL_DEBUG
+ printf("M1_and_M2 = %e + %e i\n", creals(M1_and_M2[i]), cimags(M1_and_M2[i]));
+#endif
+ assert(fabsf(creals(M1_and_M2[i]) - (creals(M1[i]) + creals(M2[i]))) / creals(M1_and_M2[i]) < 1e-07);
+ assert(fabsf(cimags(M1_and_M2[i]) - (cimags(M1[i]) + cimags(M2[i]))) / cimags(M1_and_M2[i]) < 1e-07);
+ }
+}
+
+static void saddmaTest(void) {
+ float M1[SIZE];
+ float M2[SIZE];
+ float M1_and_M2[SIZE];
+
+ int i = 0;
+
+ srand(1);
+ for (i = 0; i < SIZE; ++i) {
+ M1[i] = (float) rand();
+ M2[i] = (float) rand();
+ }
+ saddma(M1, SIZE, M2, SIZE, M1_and_M2);
+ for (i = 0; i < SIZE; ++i) {
+#ifdef LOCAL_DEBUG
+ printf("M1_and_M2 = %e\n", M1_and_M2[i]);
+ printf("M1[i] + M2[i] = %e\n", (M1[i] + M2[i]));
+ printf("Error = %e\n",(float) fabsf(M1_and_M2[i] - (M1[i] + M2[i])) / M1_and_M2[i]);
+#endif
+ assert(fabsf(M1_and_M2[i] - (M1[i] + M2[i])) / M1_and_M2[i] < 1e-07);
+ }
+}
+
+static void daddmaTest(void) {
+ double M1[SIZE];
+ double M2[SIZE];
+ double M1_and_M2[SIZE];
+
+ int i = 0;
+
+ srand(1);
+ for (i = 0; i < SIZE; ++i) {
+ M1[i] = (double) rand();
+ M2[i] = (double) rand();
+ }
+ daddma(M1, SIZE, M2, SIZE, M1_and_M2);
+ for (i = 0; i < SIZE; ++i) {
+#ifdef LOCAL_DEBUG
+ printf("M1_and_M2 = %e\n", M1_and_M2[i]);
+#endif
+ assert(fabs(M1_and_M2[i] - (M1[i] + M2[i])) == 0);
+ }
+
+}
+
+static int testAddition(void) {
+
+ printf("\n>>>> Matrix Addition Tests\n");
+ saddmaTest();
+ daddmaTest();
+ caddmaTest();
+ zaddmaTest();
+
+ return 0;
+}
+
+
+
+int main(void) {
+ assert(testAddition() == 0);
+ return 0;
+}
diff --git a/src/matrixOperations/testMatrixSubtraction.c b/src/matrixOperations/testMatrixSubtraction.c
new file mode 100644
index 00000000..5c30c4e0
--- /dev/null
+++ b/src/matrixOperations/testMatrixSubtraction.c
@@ -0,0 +1,128 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008-2008 - INRIA - Bruno JOFRET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <math.h>
+#include "matrixSubtraction.h"
+
+#define SIZE 10000
+
+/* #define LOCAL_DEBUG */
+
+static void zdiffmaTest(void) {
+ doubleComplex M1[SIZE];
+ doubleComplex M2[SIZE];
+ doubleComplex M1_but_M2[SIZE];
+
+ int i = 0;
+
+ srand(1);
+ for (i = 0; i < SIZE; ++i) {
+ M1[i] = DoubleComplex((double) rand(), (double) rand());
+ M2[i] = DoubleComplex((double) rand(), (double) rand());
+ }
+ zdiffma(M1, SIZE, M2, SIZE, M1_but_M2);
+ for (i = 0; i < SIZE; ++i) {
+#ifdef LOCAL_DEBUG
+ printf("M1_but_M2 = %e + %e i\n", zreals(M1_but_M2[i]), zimags(M1_but_M2[i]));
+#endif
+ assert(zreals(M1_but_M2[i]) - (zreals(M1[i]) - zreals(M2[i])) == 0);
+ assert(zimags(M1_but_M2[i]) - (zimags(M1[i]) - zimags(M2[i])) == 0);
+ }
+}
+
+static void cdiffmaTest(void) {
+ floatComplex M1[SIZE];
+ floatComplex M2[SIZE];
+ floatComplex M1_but_M2[SIZE];
+
+ int i = 0;
+
+ srand(1);
+ for (i = 0; i < SIZE; ++i) {
+ M1[i] = FloatComplex((float) rand(), (float) rand());
+ M2[i] = FloatComplex((float) rand(), (float) rand());
+ }
+ cdiffma(M1, SIZE, M2, SIZE, M1_but_M2);
+ for (i = 0; i < SIZE; ++i) {
+#ifdef LOCAL_DEBUG
+ printf("M1_but_M2 = %e + %e i\n", creals(M1_but_M2[i]), cimags(M1_but_M2[i]));
+#endif
+ assert(fabsf(creals(M1_but_M2[i]) - (creals(M1[i]) - creals(M2[i]))) / creals(M1_but_M2[i]) < 1e-07);
+ assert(fabsf(cimags(M1_but_M2[i]) - (cimags(M1[i]) - cimags(M2[i]))) / cimags(M1_but_M2[i]) < 1e-07);
+ }
+}
+
+static void sdiffmaTest(void) {
+ float M1[SIZE];
+ float M2[SIZE];
+ float M1_but_M2[SIZE];
+
+ int i = 0;
+
+ srand(1);
+ for (i = 0; i < SIZE; ++i) {
+ M1[i] = (float) rand();
+ M2[i] = (float) rand();
+ }
+ sdiffma(M1, SIZE, M2, SIZE, M1_but_M2);
+ for (i = 0; i < SIZE; ++i) {
+#ifdef LOCAL_DEBUG
+ printf("M1_but_M2 = %e\n", M1_but_M2[i]);
+ printf("M1[i] - M2[i] = %e\n", (M1[i] + M2[i]));
+ printf("Error = %e\n",(float) fabsf(M1_but_M2[i] - (M1[i] - M2[i])) / M1_but_M2[i]);
+#endif
+ assert(fabsf(M1_but_M2[i] - (M1[i] - M2[i])) / M1_but_M2[i] < 1e-07);
+ }
+}
+
+static void ddiffmaTest(void) {
+ double M1[SIZE];
+ double M2[SIZE];
+ double M1_but_M2[SIZE];
+
+ int i = 0;
+
+ srand(1);
+ for (i = 0; i < SIZE; ++i) {
+ M1[i] = (double) rand();
+ M2[i] = (double) rand();
+ }
+ ddiffma(M1, SIZE, M2, SIZE, M1_but_M2);
+ for (i = 0; i < SIZE; ++i) {
+#ifdef LOCAL_DEBUG
+ printf("M1_but_M2 = %e\n", M1_but_M2[i]);
+#endif
+ assert(fabs(M1_but_M2[i] - (M1[i] - M2[i])) == 0);
+ }
+
+}
+
+static int testDiffition(void) {
+
+ printf("\n>>>> Matrix Substraction Tests\n");
+ sdiffmaTest();
+ ddiffmaTest();
+ cdiffmaTest();
+ zdiffmaTest();
+
+ return 0;
+}
+
+
+
+int main(void) {
+ assert(testDiffition() == 0);
+ return 0;
+}