From patchwork Thu Jun 16 21:37:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Barker X-Patchwork-Id: 2015 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 4BBDE23F3D for ; Thu, 16 Jun 2011 21:37:17 +0000 (UTC) Received: from mail-vw0-f52.google.com (mail-vw0-f52.google.com [209.85.212.52]) by fiordland.canonical.com (Postfix) with ESMTP id DFFBBA18472 for ; Thu, 16 Jun 2011 21:37:16 +0000 (UTC) Received: by vws16 with SMTP id 16so881547vws.11 for ; Thu, 16 Jun 2011 14:37:16 -0700 (PDT) Received: by 10.52.100.72 with SMTP id ew8mr1930929vdb.247.1308260235365; Thu, 16 Jun 2011 14:37:15 -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.52.183.130 with SMTP id em2cs213998vdc; Thu, 16 Jun 2011 14:37:14 -0700 (PDT) Received: by 10.217.5.130 with SMTP id w2mr1418871wes.61.1308260233687; Thu, 16 Jun 2011 14:37:13 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id v13si5160539wer.115.2011.06.16.14.37.13; Thu, 16 Jun 2011 14:37:13 -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 1QXKFV-0003wC-2G for ; Thu, 16 Jun 2011 21:37:13 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 0EC1C2E899B for ; Thu, 16 Jun 2011 21:37:13 +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: 17 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~jesse-barker/libmatrix/trunk] Rev 17: Add matrix_inverse_test and build it by default. Message-Id: <20110616213713.13415.92161.launchpad@loganberry.canonical.com> Date: Thu, 16 Jun 2011 21:37:13 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13216"; Instance="initZopeless config overlay" X-Launchpad-Hash: 3b4223f0c608455e10147f4f693dfffdba3f42ff ------------------------------------------------------------ revno: 17 committer: Jesse Barker branch nick: trunk timestamp: Thu 2011-06-16 14:35:35 -0700 message: Add matrix_inverse_test and build it by default. added: matrix_inverse_test.cc modified: Makefile --- 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-09 20:36:25 +0000 +++ Makefile 2011-06-16 21:35:35 +0000 @@ -1,13 +1,15 @@ -TARGETS = libmatrix.a -SRCS = mat.cc program.cc +TARGETS = libmatrix.a matrix_inverse_test +SRCS = mat.cc program.cc matrix_inverse_test.cc OBJS = $(SRCS:.cc=.o) CXXFLAGS = -Wall -Werror -pedantic -O3 default: $(TARGETS) mat.o : mat.cc mat.h -program.o: program.o program.h - +program.o: program.cc program.h +matrix_inverse_test.o: matrix_inverse_test.cc mat.h +matrix_inverse_test: matrix_inverse_test.o libmatrix.a + $(CXX) -o $@ $? libmatrix.a : mat.o mat.h stack.h vec.h program.o program.h $(AR) -r $@ $(OBJS) === added file 'matrix_inverse_test.cc' --- matrix_inverse_test.cc 1970-01-01 00:00:00 +0000 +++ matrix_inverse_test.cc 2011-06-16 21:35:35 +0000 @@ -0,0 +1,141 @@ +#include +#include "mat.h" + +using LibMatrix::mat4; +using LibMatrix::mat3; +using LibMatrix::mat2; +using std::cerr; +using std::cout; +using std::endl; + +bool mat2OK() +{ + mat2 m; + cout << "Starting with mat2 (should be identity): " << endl << endl; + m.print(); + + m[0][1] = -2.5; + + cout << endl << "Matrix should now have (0, 1) == -2.500000" << endl << endl; + m.print(); + + mat2 mi(m); + + cout << endl << "Copy of previous matrix (should have (0, 1) == -2.500000)" << endl << endl; + mi.print(); + + mi.inverse(); + + cout << endl << "Inverse of copy: " << endl << endl; + mi.print(); + + mat2 i = m * mi; + + cout << endl << "Product of original and inverse (should be identity): " << endl << endl; + i.print(); + + mat2 ident; + if (i != ident) + { + return false; + } + + return true; +} + +bool mat3OK() +{ + mat3 m; + cout << "Starting with mat3 (should be identity): " << endl << endl; + m.print(); + + m[1][2] = -2.5; + + cout << endl << "Matrix should now have (1, 2) == -2.500000" << endl << endl; + m.print(); + + mat3 mi(m); + + cout << endl << "Copy of previous matrix (should have (1, 2) == -2.500000)" << endl << endl; + mi.print(); + + mi.inverse(); + + cout << endl << "Inverse of copy: " << endl << endl; + mi.print(); + + mat3 i = m * mi; + + cout << endl << "Product of original and inverse (should be identity): " << endl << endl; + i.print(); + + mat3 ident; + if (i != ident) + { + return false; + } + + return true; +} + +bool mat4OK() +{ + mat4 m; + cout << "Starting with mat4 (should be identity): " << endl << endl; + m.print(); + + m[2][3] = -2.5; + + cout << endl << "Matrix should now have (2, 3) == -2.500000" << endl << endl; + m.print(); + + mat4 mi(m); + + cout << endl << "Copy of previous matrix (should have (2, 3) == -2.500000)" << endl << endl; + mi.print(); + + mi.inverse(); + + cout << endl << "Inverse of copy: " << endl << endl; + mi.print(); + + mat4 i = m * mi; + + cout << endl << "Product of original and inverse (should be identity): " << endl << endl; + i.print(); + + mat4 ident; + if (i != ident) + { + return false; + } + + return true; +} + +int +main(int argc, char** argv) +{ + if (!mat2OK()) + { + cerr << "mat2::inverse() does not work!" << endl; + return 1; + } + cout << "mat2::inverse() is okay!" << endl << endl; + + if (!mat3OK()) + { + cerr << "mat3::inverse() does not work!" << endl; + return 1; + } + cout << "mat3::inverse() is okay!" << endl << endl; + + if (!mat4OK()) + { + cerr << "mat4::inverse() does not work!" << endl; + return 1; + } + cout << "mat4::inverse() is okay!" << endl << endl; + + return 0; +}