From patchwork Wed Jun 22 23:13:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Barker X-Patchwork-Id: 2188 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D985B23F08 for ; Wed, 22 Jun 2011 23:13:28 +0000 (UTC) Received: from mail-gx0-f180.google.com (mail-gx0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 73446A180DF for ; Wed, 22 Jun 2011 23:13:28 +0000 (UTC) Received: by gxk10 with SMTP id 10so996517gxk.11 for ; Wed, 22 Jun 2011 16:13:28 -0700 (PDT) Received: by 10.150.56.38 with SMTP id e38mr1498799yba.113.1308784407885; Wed, 22 Jun 2011 16:13:27 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.151.157.9 with SMTP id j9cs122082ybo; Wed, 22 Jun 2011 16:13:27 -0700 (PDT) Received: by 10.227.208.12 with SMTP id ga12mr1254742wbb.68.1308784405956; Wed, 22 Jun 2011 16:13:25 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id fq6si2502309wbb.15.2011.06.22.16.13.25; Wed, 22 Jun 2011 16:13:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QZWbt-0007WZ-5u for ; Wed, 22 Jun 2011 23:13:25 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 2596F2E8019 for ; Wed, 22 Jun 2011 23:13:25 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: libmatrix X-Launchpad-Branch: ~jesse-barker/libmatrix/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 21 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~jesse-barker/libmatrix/trunk] Rev 21: Add transpose tests for matrix classes. Also, add copyright comments to test Message-Id: <20110622231325.20352.41085.launchpad@loganberry.canonical.com> Date: Wed, 22 Jun 2011 23:13:25 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13265"; Instance="initZopeless config overlay" X-Launchpad-Hash: 5e361dc8825dd1e68a9f3e2d0f85884e7d306b90 ------------------------------------------------------------ revno: 21 committer: Jesse Barker branch nick: trunk timestamp: Wed 2011-06-22 16:11:46 -0700 message: Add transpose tests for matrix classes. Also, add copyright comments to test modules and fixup the final link rule for creating the test executable. added: test/transpose_test.cc test/transpose_test.h modified: Makefile test/inverse_test.cc test/inverse_test.h test/libmatrix_test.cc test/libmatrix_test.h test/options.cc --- lp:libmatrix https://code.launchpad.net/~jesse-barker/libmatrix/trunk You are subscribed to branch lp:libmatrix. To unsubscribe from this branch go to https://code.launchpad.net/~jesse-barker/libmatrix/trunk/+edit-subscription === modified file 'Makefile' --- Makefile 2011-06-21 22:37:41 +0000 +++ Makefile 2011-06-22 23:11:46 +0000 @@ -6,6 +6,7 @@ LIBMATRIX_TESTS = $(TESTDIR)/libmatrix_test TESTSRCS = $(TESTDIR)/options.cc \ $(TESTDIR)/inverse_test.cc \ + $(TESTDIR)/transpose_test.cc \ $(TESTDIR)/libmatrix_test.cc TESTOBJS = $(TESTSRCS:.cc=.o) @@ -21,10 +22,11 @@ # Tests and execution targets here. $(TESTDIR)/options.o: $(TESTDIR)/options.cc $(TESTDIR)/libmatrix_test.h -$(TESTDIR)/libmatrix_test.o: $(TESTDIR)/libmatrix_test.cc $(TESTDIR)/libmatrix_test.h $(TESTDIR)/inverse_test.h +$(TESTDIR)/libmatrix_test.o: $(TESTDIR)/libmatrix_test.cc $(TESTDIR)/libmatrix_test.h $(TESTDIR)/inverse_test.h $(TESTDIR)/transpose_test.h $(TESTDIR)/inverse_test.o: $(TESTDIR)/inverse_test.cc $(TESTDIR)/inverse_test.h $(TESTDIR)/libmatrix_test.h mat.h -$(TESTDIR)/libmatrix_test: $(TESTDIR)/options.o $(TESTDIR)/libmatrix_test.o $(TESTDIR)/inverse_test.o libmatrix.a - $(CXX) -o $@ $? +$(TESTDIR)/transpose_test.o: $(TESTDIR)/transpose_test.cc $(TESTDIR)/transpose_test.h $(TESTDIR)/libmatrix_test.h mat.h +$(TESTDIR)/libmatrix_test: $(TESTOBJS) libmatrix.a + $(CXX) -o $@ $^ run_tests: $(LIBMATRIX_TESTS) $(LIBMATRIX_TESTS) clean : === modified file 'test/inverse_test.cc' --- test/inverse_test.cc 2011-06-21 22:37:41 +0000 +++ test/inverse_test.cc 2011-06-22 23:11:46 +0000 @@ -1,3 +1,14 @@ +// +// Copyright (c) 2010 Linaro Limited +// +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the MIT License which accompanies +// this distribution, and is available at +// http://www.opensource.org/licenses/mit-license.php +// +// Contributors: +// Jesse Barker - original implementation. +// #include #include "libmatrix_test.h" #include "inverse_test.h" === modified file 'test/inverse_test.h' --- test/inverse_test.h 2011-06-21 22:37:41 +0000 +++ test/inverse_test.h 2011-06-22 23:11:46 +0000 @@ -1,3 +1,14 @@ +// +// Copyright (c) 2010 Linaro Limited +// +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the MIT License which accompanies +// this distribution, and is available at +// http://www.opensource.org/licenses/mit-license.php +// +// Contributors: +// Jesse Barker - original implementation. +// #ifndef INVERSE_TEST_H_ #define INVERSE_TEST_H_ === modified file 'test/libmatrix_test.cc' --- test/libmatrix_test.cc 2011-06-21 22:37:41 +0000 +++ test/libmatrix_test.cc 2011-06-22 23:11:46 +0000 @@ -14,6 +14,7 @@ #include #include "libmatrix_test.h" #include "inverse_test.h" +#include "transpose_test.h" using std::cerr; using std::cout; @@ -35,12 +36,19 @@ testVec.push_back(new MatrixTest2x2Inverse()); testVec.push_back(new MatrixTest3x3Inverse()); testVec.push_back(new MatrixTest4x4Inverse()); + testVec.push_back(new MatrixTest2x2Transpose()); + testVec.push_back(new MatrixTest3x3Transpose()); + testVec.push_back(new MatrixTest4x4Transpose()); for (vector::iterator testIt = testVec.begin(); testIt != testVec.end(); testIt++) { MatrixTest* curTest = *testIt; + if (testOptions.beVerbose()) + { + cout << "Running test " << curTest->name() << endl; + } curTest->run(testOptions); if (!curTest->passed()) { === modified file 'test/libmatrix_test.h' --- test/libmatrix_test.h 2011-06-21 22:37:41 +0000 +++ test/libmatrix_test.h 2011-06-22 23:11:46 +0000 @@ -1,3 +1,14 @@ +// +// Copyright (c) 2010 Linaro Limited +// +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the MIT License which accompanies +// this distribution, and is available at +// http://www.opensource.org/licenses/mit-license.php +// +// Contributors: +// Jesse Barker - original implementation. +// #ifndef LIBMATRIX_TEST_H_ #define LIBMATRIX_TEST_H_ === modified file 'test/options.cc' --- test/options.cc 2011-06-21 22:37:41 +0000 +++ test/options.cc 2011-06-22 23:11:46 +0000 @@ -1,3 +1,14 @@ +// +// Copyright (c) 2010 Linaro Limited +// +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the MIT License which accompanies +// this distribution, and is available at +// http://www.opensource.org/licenses/mit-license.php +// +// Contributors: +// Jesse Barker - original implementation. +// #include #include #include === added file 'test/transpose_test.cc' --- test/transpose_test.cc 1970-01-01 00:00:00 +0000 +++ test/transpose_test.cc 2011-06-22 23:11:46 +0000 @@ -0,0 +1,297 @@ +// +// Copyright (c) 2010 Linaro Limited +// +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the MIT License which accompanies +// this distribution, and is available at +// http://www.opensource.org/licenses/mit-license.php +// +// Contributors: +// Jesse Barker - original implementation. +// +#include +#include "libmatrix_test.h" +#include "transpose_test.h" +#include "../mat.h" + +using LibMatrix::mat2; +using LibMatrix::mat3; +using LibMatrix::mat4; +using std::cout; +using std::endl; + +void +MatrixTest2x2Transpose::run(const Options& options) +{ + // First, a simple test to ensure that the transpose of the identity is + // the identity. + if (options.beVerbose()) + { + cout << endl << "Assertion 1: Transpose of the identity is the identity." << endl << endl; + } + + mat2 m; + + if (options.beVerbose()) + { + cout << "Starting with mat2 (should be identity): " << endl << endl; + m.print(); + } + + m.transpose(); + + if (options.beVerbose()) + { + cout << endl << "Transpose of identity (should be identity): " << endl << endl; + m.print(); + } + + mat2 mi; + if (m != mi) + { + // FAIL! Transpose of the identity is the identity. + return; + } + + // At this point, we have 2 identity matrices. + // Next, set an element in the matrix and transpose twice. We should see + // the original matrix (with i,j set). + if (options.beVerbose()) + { + cout << endl << "Assertion 2: Transposing a matrix twice yields the original matrix." << endl << endl; + } + + m[0][1] = 6.3; + + if (options.beVerbose()) + { + cout << "Matrix should now have (0, 1) == 6.300000" << endl << endl; + m.print(); + } + + mi = m; + + m.transpose().transpose(); + + if (options.beVerbose()) + { + cout << endl << "Matrix should now have (0, 1) == 6.300000" << endl << endl; + m.print(); + } + + if (m != mi) + { + // FAIL! Transposing the same matrix twice should yield the original. + return; + } + + // Next, reset mi back to the identity. Set element element j,i in this + // matrix and transpose m. They should now be equal. + if (options.beVerbose()) + { + cout << endl << "Assertion 3: Transpose of matrix (i,j) == x is equal to matrix (j,i) == x." << endl << endl; + } + + mi.setIdentity(); + mi[1][0] = 6.3; + + m.transpose(); + + if (options.beVerbose()) + { + cout << "Matrix should now have (1, 0) == 6.300000" << endl << endl; + m.print(); + cout << endl; + } + + if (m == mi) + { + pass_ = true; + } + + // FAIL! Transposing the same matrix twice should yield the original. +} + +void +MatrixTest3x3Transpose::run(const Options& options) +{ + // First, a simple test to ensure that the transpose of the identity is + // the identity. + if (options.beVerbose()) + { + cout << endl << "Assertion 1: Transpose of the identity is the identity." << endl << endl; + } + + mat3 m; + + if (options.beVerbose()) + { + cout << "Starting with mat2 (should be identity): " << endl << endl; + m.print(); + } + + m.transpose(); + + if (options.beVerbose()) + { + cout << endl << "Transpose of identity (should be identity): " << endl << endl; + m.print(); + } + + mat3 mi; + if (m != mi) + { + // FAIL! Transpose of the identity is the identity. + return; + } + + // At this point, we have 2 identity matrices. + // Next, set an element in the matrix and transpose twice. We should see + // the original matrix (with i,j set). + if (options.beVerbose()) + { + cout << endl << "Assertion 2: Transposing a matrix twice yields the original matrix." << endl << endl; + } + + m[0][1] = 6.3; + + if (options.beVerbose()) + { + cout << "Matrix should now have (0, 1) == 6.300000" << endl << endl; + m.print(); + } + + mi = m; + + m.transpose().transpose(); + + if (options.beVerbose()) + { + cout << endl << "Matrix should now have (0, 1) == 6.300000" << endl << endl; + m.print(); + } + + if (m != mi) + { + // FAIL! Transposing the same matrix twice should yield the original. + return; + } + + // Next, reset mi back to the identity. Set element element j,i in this + // matrix and transpose m. They should now be equal. + if (options.beVerbose()) + { + cout << endl << "Assertion 3: Transpose of matrix (i,j) == x is equal to matrix (j,i) == x." << endl << endl; + } + + mi.setIdentity(); + mi[1][0] = 6.3; + + m.transpose(); + + if (options.beVerbose()) + { + cout << "Matrix should now have (1, 0) == 6.300000" << endl << endl; + m.print(); + cout << endl; + } + + if (m == mi) + { + pass_ = true; + } + + // FAIL! Transposing the same matrix twice should yield the original. +} + +void +MatrixTest4x4Transpose::run(const Options& options) +{ + // First, a simple test to ensure that the transpose of the identity is + // the identity. + if (options.beVerbose()) + { + cout << endl << "Assertion 1: Transpose of the identity is the identity." << endl << endl; + } + + mat4 m; + + if (options.beVerbose()) + { + cout << "Starting with mat2 (should be identity): " << endl << endl; + m.print(); + } + + m.transpose(); + + if (options.beVerbose()) + { + cout << endl << "Transpose of identity (should be identity): " << endl << endl; + m.print(); + } + + mat4 mi; + if (m != mi) + { + // FAIL! Transpose of the identity is the identity. + return; + } + + // At this point, we have 2 identity matrices. + // Next, set an element in the matrix and transpose twice. We should see + // the original matrix (with i,j set). + if (options.beVerbose()) + { + cout << endl << "Assertion 2: Transposing a matrix twice yields the original matrix." << endl << endl; + } + + m[0][1] = 6.3; + + if (options.beVerbose()) + { + cout << "Matrix should now have (0, 1) == 6.300000" << endl << endl; + m.print(); + } + + mi = m; + + m.transpose().transpose(); + + if (options.beVerbose()) + { + cout << endl << "Matrix should now have (0, 1) == 6.300000" << endl << endl; + m.print(); + } + + if (m != mi) + { + // FAIL! Transposing the same matrix twice should yield the original. + return; + } + + // Next, reset mi back to the identity. Set element element j,i in this + // matrix and transpose m. They should now be equal. + if (options.beVerbose()) + { + cout << endl << "Assertion 3: Transpose of matrix (i,j) == x is equal to matrix (j,i) == x." << endl << endl; + } + + mi.setIdentity(); + mi[1][0] = 6.3; + + m.transpose(); + + if (options.beVerbose()) + { + cout << "Matrix should now have (1, 0) == 6.300000" << endl << endl; + m.print(); + cout << endl; + } + + if (m == mi) + { + pass_ = true; + } + + // FAIL! Transposing the same matrix twice should yield the original. +} === added file 'test/transpose_test.h' --- test/transpose_test.h 1970-01-01 00:00:00 +0000 +++ test/transpose_test.h 2011-06-22 23:11:46 +0000 @@ -0,0 +1,38 @@ +// +// Copyright (c) 2010 Linaro Limited +// +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the MIT License which accompanies +// this distribution, and is available at +// http://www.opensource.org/licenses/mit-license.php +// +// Contributors: +// Jesse Barker - original implementation. +// +#ifndef TRANSPOSE_TEST_H_ +#define TRANSPOSE_TEST_H_ + +class MatrixTest; +class Options; + +class MatrixTest2x2Transpose : public MatrixTest +{ +public: + MatrixTest2x2Transpose() : MatrixTest("mat2::transpose") {} + virtual void run(const Options& options); +}; + +class MatrixTest3x3Transpose : public MatrixTest +{ +public: + MatrixTest3x3Transpose() : MatrixTest("mat3::transpose") {} + virtual void run(const Options& options); +}; + +class MatrixTest4x4Transpose : public MatrixTest +{ +public: + MatrixTest4x4Transpose() : MatrixTest("mat4::transpose") {} + virtual void run(const Options& options); +}; +#endif // TRANSPOSE_TEST_H_