From 5bbeda0bb4d4fecb78ceb187feab9dbc29677666 Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Mon, 12 Sep 2011 14:11:52 +0200
Subject: [PATCH] Tests based on manual computations

---
 src/test-gradient-method.cc | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/src/test-gradient-method.cc b/src/test-gradient-method.cc
index 9174af83..9c336006 100644
--- a/src/test-gradient-method.cc
+++ b/src/test-gradient-method.cc
@@ -8,6 +8,8 @@
 
 #include "samplefunctional.hh"
 
+#include <cassert>
+
 template <int dim, class Function>
 void functionTester(
     Dune::SampleFunctional<dim, Function> J,
@@ -42,6 +44,19 @@ void testSampleFunction() {
   SampleFunctional::SmallVector start = b;
   start *= 17;
 
+  /*
+    j(x)
+    = Ax - b + 2/|x| x
+    = 17*(6, 9.5) - (1, 2) + 2/sqrt(5) (1, 2)
+    = (102 - 1 + 2/sqrt(5), 161.5 - 2 + 4/sqrt(5))
+  */
+  SampleFunctional::SmallVector error;
+  error[0] = -(102 - 1 + 2 / sqrt(5));
+  error[1] = -(161.5 - 2 + 4 / sqrt(5));
+  SampleFunctional::SmallVector returned = J.descentDirection(start);
+  error -= returned;
+  assert(error.two_norm() < 1e-10); // FIXME: 1e-10 sounds reasonable. Is it?
+
   functionTester(J, start, 6);
 }
 
@@ -63,6 +78,19 @@ void testTrivialFunction() {
   SampleFunctional::SmallVector start = b;
   start *= 17;
 
+  /*
+    j(x)
+    = Ax - b
+    = 17*(6, 9.5) - (1, 2)
+    = (102 - 1, 161.5 - 2)
+  */
+  SampleFunctional::SmallVector error;
+  error[0] = -101;
+  error[1] = -159.5;
+  SampleFunctional::SmallVector returned = J.descentDirection(start);
+  error -= returned;
+  assert(error.two_norm() < 1e-10); // FIXME: 1e-10 sounds reasonable. Is it?
+
   functionTester(J, start, 5);
 }
 
-- 
GitLab