From 5b7eb847a3026a09a2b275e209f8a24ccf7fd604 Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Wed, 1 Aug 2012 11:50:16 +0200
Subject: [PATCH] Use initialiser lists

---
 src/test-circle.cc                        | 26 +++----------
 src/test-gradient-horrible-logarithmic.cc | 40 +++++++++----------
 src/test-gradient-horrible.cc             | 40 +++++++++----------
 src/test-gradient-identity.cc             | 40 +++++++++----------
 src/test-gradient-parabola.cc             | 19 ++-------
 src/test-gradient-sample-3d.cc            | 45 +++++++++-------------
 src/test-gradient-sample-nonsmooth.cc     | 18 +++------
 src/test-gradient-sample-steep.cc         | 42 +++++++++-----------
 src/test-gradient-sample-steep2.cc        | 42 +++++++++-----------
 src/test-gradient-sample-verysteep.cc     | 42 +++++++++-----------
 src/test-gradient-sample.cc               | 47 +++++++++++------------
 src/test-gradient-sample2.cc              | 39 +++++++++----------
 src/test-gradient-trivial.cc              | 17 ++------
 13 files changed, 194 insertions(+), 263 deletions(-)

diff --git a/src/test-circle.cc b/src/test-circle.cc
index a7f308e4..9489723c 100644
--- a/src/test-circle.cc
+++ b/src/test-circle.cc
@@ -26,13 +26,8 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A;
-  A[0][0] = 4;
-  A[0][1] = A[1][0] = 1.5;
-  A[1][1] = 3;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 2;
+  SmallMatrix A = { { 4, 1.5 }, { 1.5, 3 } };
+  SmallVector b = { 1, 2 };
 
   auto const f = Dune::make_shared<Dune::SampleFunction<2> const>();
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
@@ -49,12 +44,8 @@ int main() {
   boost::format const formatter("J([%+e]) = %g");
 
   for (size_t i = 0; i < radii.size(); ++i) {
-    SmallVector x;
-    x[0] = scale * std::sin(radii[i]);
-    x[1] = scale * std::cos(radii[i]);
-    SmallVector descDir;
-    descDir[0] = x[1];
-    descDir[1] = -x[0];
+    SmallVector x = { scale * std::sin(radii[i]), scale * std::cos(radii[i]) };
+    SmallVector descDir = { x[1], -x[0] };
     tangentialMinimisation(J, x, descDir, bisection);
     minima[i] = x;
     std::cout << boost::format(formatter) % x % J(x) << std::endl;
@@ -63,13 +54,8 @@ int main() {
   double const intervals = 10000;
   for (size_t i = 0; i < intervals; ++i) {
     double const alpha = i / (double)intervals * 2 * M_PI;
-    SmallVector x;
-    x[0] = scale * std::sin(alpha);
-    x[1] = scale * std::cos(alpha);
-
-    SmallVector descDir;
-    descDir[0] = x[1];
-    descDir[1] = -x[0];
+    SmallVector x = { scale * std::sin(alpha), scale * std::cos(alpha) };
+    SmallVector descDir = { x[1], -x[0] };
     tangentialMinimisation(J, x, descDir, bisection);
 
     bool minimum_hit(false);
diff --git a/src/test-gradient-horrible-logarithmic.cc b/src/test-gradient-horrible-logarithmic.cc
index 9507dcfe..950a776c 100644
--- a/src/test-gradient-horrible-logarithmic.cc
+++ b/src/test-gradient-horrible-logarithmic.cc
@@ -19,33 +19,31 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A;
-  A[0][0] = 3;
-  A[0][1] = A[1][0] = 1.5;
-  A[1][1] = 4;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 2;
+  SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } };
+  SmallVector b = { 1, 2 };
 
   auto const f = Dune::make_shared<Dune::HorribleFunctionLogarithmic const>();
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
   Functional J(A, b, phi);
 
-  SmallVector start = b;
-  start *= 17;
-
-  double const ret1 = functionTester(J, start, 6);
-
-  // Something random
-  start[0] = 279;
-  start[1] = -96;
-
-  double const ret2 = functionTester(J, start, 12);
+  double ret1;
+  {
+    SmallVector start = { 17, 34 };
+    ret1 = functionTester(J, start, 6);
+  }
+
+  double ret2;
+  {
+    // Something random
+    SmallVector start = { 279, -96 };
+    ret2 = functionTester(J, start, 12);
+  }
   assert(std::abs(ret1 - ret2) < 1e-5);
 
-  start[0] = 0;
-  start[1] = 0;
-
-  double const ret3 = functionTester(J, start, 4);
+  double ret3;
+  {
+    SmallVector start = { 0, 0 };
+    ret3 = functionTester(J, start, 4);
+  }
   assert(std::abs(ret1 - ret3) < 1e-5);
 }
diff --git a/src/test-gradient-horrible.cc b/src/test-gradient-horrible.cc
index e3215d00..14de1df5 100644
--- a/src/test-gradient-horrible.cc
+++ b/src/test-gradient-horrible.cc
@@ -19,33 +19,31 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A;
-  A[0][0] = 3;
-  A[0][1] = A[1][0] = 1.5;
-  A[1][1] = 4;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 2;
+  SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } };
+  SmallVector b = { 1, 2 };
 
   auto const f = Dune::make_shared<Dune::HorribleFunction const>();
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
   Functional J(A, b, phi);
 
-  SmallVector start = b;
-  start *= 17;
-
-  double const ret1 = functionTester(J, start, 7);
-
-  // Something random
-  start[0] = 279;
-  start[1] = -96;
-
-  double const ret2 = functionTester(J, start, 8);
+  double ret1;
+  {
+    SmallVector start = { 17, 34 };
+    ret1 = functionTester(J, start, 7);
+  }
+
+  double ret2;
+  {
+    // Something random
+    SmallVector start = { 279, -96 };
+    ret2 = functionTester(J, start, 8);
+  }
   assert(std::abs(ret1 - ret2) < 1e-5);
 
-  start[0] = 0;
-  start[1] = 0;
-
-  double const ret3 = functionTester(J, start, 4);
+  double ret3;
+  {
+    SmallVector start = { 0, 0 };
+    ret3 = functionTester(J, start, 4);
+  }
   assert(std::abs(ret1 - ret3) < 1e-5);
 }
diff --git a/src/test-gradient-identity.cc b/src/test-gradient-identity.cc
index 82eac754..a9ba32e8 100644
--- a/src/test-gradient-identity.cc
+++ b/src/test-gradient-identity.cc
@@ -19,33 +19,31 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A;
-  A[0][0] = 3;
-  A[0][1] = A[1][0] = 1.5;
-  A[1][1] = 4;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 2;
+  SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } };
+  SmallVector b = { 1, 2 };
 
   auto const f = Dune::make_shared<Dune::LinearFunction const>(1);
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
   Functional J(A, b, phi);
 
-  SmallVector start = b;
-  start *= 17;
-
-  double const ret1 = functionTester(J, start, 6);
-
-  // Something random
-  start[0] = 279;
-  start[1] = -96;
-
-  double const ret2 = functionTester(J, start, 10);
+  double ret1;
+  {
+    SmallVector start = { 17, 34 };
+    ret1 = functionTester(J, start, 6);
+  }
+
+  double ret2;
+  {
+    // Something random
+    SmallVector start = { 279, -96 };
+    ret2 = functionTester(J, start, 10);
+  }
   assert(std::abs(ret1 - ret2) < 1e-5);
 
-  start[0] = 0;
-  start[1] = 0;
-
-  double const ret3 = functionTester(J, start, 3);
+  double ret3;
+  {
+    SmallVector start = { 0, 0 };
+    ret3 = functionTester(J, start, 3);
+  }
   assert(std::abs(ret1 - ret3) < 1e-5);
 }
diff --git a/src/test-gradient-parabola.cc b/src/test-gradient-parabola.cc
index cce5f56b..a1d3d802 100644
--- a/src/test-gradient-parabola.cc
+++ b/src/test-gradient-parabola.cc
@@ -21,13 +21,8 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A;
-  A[0][0] = 3;
-  A[0][1] = A[1][0] = 1.5;
-  A[1][1] = 4;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 2;
+  SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } };
+  SmallVector b = { 1, 2 };
 
   // |x|^2 as the nonlinearity is the same as having no nonlinearity
   // but twice the identity matrix added to A. In other words, we're
@@ -36,10 +31,7 @@ int main() {
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
   Functional J(A, b, phi);
 
-  SmallVector solution; // Analytic solution
-  solution[0] = 4.0 / 37.0;
-  solution[1] = 34.0 / 111.0;
-
+  SmallVector solution = { 4.0 / 37.0, 34.0 / 111.0 }; // Analytic solution
   SmallMatrix M = A;
   M[0][0] += 2;
   M[1][1] += 2;
@@ -63,10 +55,7 @@ int main() {
   double ret2;
   {
     // Something random
-    SmallVector start;
-    start[0] = 279;
-    start[1] = -96;
-
+    SmallVector start = { 279, -96 };
     SmallVector analytic_descent = b;
     M.mmv(start, analytic_descent);
 
diff --git a/src/test-gradient-sample-3d.cc b/src/test-gradient-sample-3d.cc
index ae2cb3e0..e57d2b84 100644
--- a/src/test-gradient-sample-3d.cc
+++ b/src/test-gradient-sample-3d.cc
@@ -19,38 +19,31 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A(0);
-  A[0][0] = 3;
-  A[0][1] = A[1][0] = 1.5;
-  A[1][1] = 4;
-  A[1][2] = A[2][1] = 1.5;
-  A[2][2] = 5;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 2;
-  b[2] = 3;
+  SmallMatrix A = { { 3, 1.5, 0 }, { 1.5, 4, 1.5 }, { 0, 1.5, 5 } };
+  SmallVector b = { 1, 2, 3 };
 
   auto const f = Dune::make_shared<Dune::SampleFunction<2> const>();
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
   Functional J(A, b, phi);
 
-  SmallVector start = b;
-  start *= 17;
-
-  double const ret1 = functionTester(J, start, 9);
-
-  // Something random
-  start[0] = 279;
-  start[1] = -96;
-  start[2] = -15;
-
-  double const ret2 = functionTester(J, start, 15);
+  double ret1;
+  {
+    SmallVector start = { 17, 34, 51 };
+    ret1 = functionTester(J, start, 9);
+  }
+
+  double ret2;
+  {
+    // Something random
+    SmallVector start = { 279, -96, -15 };
+    ret2 = functionTester(J, start, 15);
+  }
   assert(std::abs(ret1 - ret2) < 1e-5);
 
-  start[0] = 0;
-  start[1] = 0;
-  start[2] = 0;
-
-  double const ret3 = functionTester(J, start, 5);
+  double ret3;
+  {
+    SmallVector start = { 0, 0, 0 };
+    ret3 = functionTester(J, start, 5);
+  }
   assert(std::abs(ret1 - ret3) < 1e-5);
 }
diff --git a/src/test-gradient-sample-nonsmooth.cc b/src/test-gradient-sample-nonsmooth.cc
index e8f49226..63c8034f 100644
--- a/src/test-gradient-sample-nonsmooth.cc
+++ b/src/test-gradient-sample-nonsmooth.cc
@@ -20,20 +20,14 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A;
-  A[0][0] = 3;
-  A[0][1] = A[1][0] = 1.5;
-  A[1][1] = 4;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 2;
+  SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } };
+  SmallVector b = { 1, 2 };
 
   auto const f = Dune::make_shared<Dune::SampleFunction<2> const>();
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
   Functional J(A, b, phi);
 
   SmallVector start;
-  SmallVector analytic_descent;
   /*
     for x = b/|b|:
 
@@ -54,8 +48,8 @@ int main() {
 
     SmallVector numerical_descent;
     J.descentDirection(start, numerical_descent);
-    analytic_descent[0] = -(7 / sqrt(5) - 1);
-    analytic_descent[1] = -(11.5 / sqrt(5) - 2);
+    SmallVector analytic_descent = { -(7 / sqrt(5) - 1),
+                                     -(11.5 / sqrt(5) - 2) };
     assert(two_distance<dim>(analytic_descent, numerical_descent) < 1e-10);
 
     functionTester(J, start, 6);
@@ -67,8 +61,8 @@ int main() {
 
     SmallVector numerical_descent;
     J.descentDirection(start, numerical_descent);
-    analytic_descent[0] = -(8 / sqrt(5) - 1);
-    analytic_descent[1] = -(13.5 / sqrt(5) - 2);
+    SmallVector analytic_descent = { -(8 / sqrt(5) - 1),
+                                     -(13.5 / sqrt(5) - 2) };
     assert(two_distance<dim>(analytic_descent, numerical_descent) < 1e-10);
 
     functionTester(J, start, 6);
diff --git a/src/test-gradient-sample-steep.cc b/src/test-gradient-sample-steep.cc
index 3cd290dd..3bc51bef 100644
--- a/src/test-gradient-sample-steep.cc
+++ b/src/test-gradient-sample-steep.cc
@@ -19,35 +19,31 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A;
-  A[0][0] = 1;
-  A[0][1] = A[1][0] = 0;
-  A[1][1] = 1;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 2;
+  SmallMatrix A = { { 1, 0 }, { 0, 1 } };
+  SmallVector b = { 1, 2 };
 
   auto const f = Dune::make_shared<Dune::SampleFunction<2> const>();
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
   Functional J(A, b, phi);
 
-  SmallVector start;
-
-  start[0] = 0;
-  start[1] = 1;
-
-  double const ret1 = functionTester(J, start, 3);
-
-  // Something random
-  start[0] = 279;
-  start[1] = -96;
-
-  double const ret2 = functionTester(J, start, 3);
+  double ret1;
+  {
+    SmallVector start = { 0, 1 };
+    ret1 = functionTester(J, start, 3);
+  }
+
+  double ret2;
+  {
+    // Something random
+    SmallVector start = { 279, -96 };
+    ret2 = functionTester(J, start, 3);
+  }
   assert(std::abs(ret1 - ret2) < 1e-5);
 
-  start[0] = 0;
-  start[1] = 0;
-
-  double const ret3 = functionTester(J, start, 1);
+  double ret3;
+  {
+    SmallVector start = { 0, 0 };
+    ret3 = functionTester(J, start, 1);
+  }
   assert(std::abs(ret1 - ret3) < 1e-5);
 }
diff --git a/src/test-gradient-sample-steep2.cc b/src/test-gradient-sample-steep2.cc
index abbd2899..f77c3788 100644
--- a/src/test-gradient-sample-steep2.cc
+++ b/src/test-gradient-sample-steep2.cc
@@ -19,35 +19,31 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A;
-  A[0][0] = 1;
-  A[0][1] = A[1][0] = 0;
-  A[1][1] = 1;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 2.5;
+  SmallMatrix A = { { 1, 0 }, { 0, 1 } };
+  SmallVector b = { 1, 2.5 };
 
   auto const f = Dune::make_shared<Dune::SampleFunction<2> const>();
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
   Functional J(A, b, phi);
 
-  SmallVector start;
-
-  start[0] = 0;
-  start[1] = 1;
-
-  double const ret1 = functionTester(J, start, 1);
-
-  // Something random
-  start[0] = 279;
-  start[1] = -96;
-
-  double const ret2 = functionTester(J, start, 3);
+  double ret1;
+  {
+    SmallVector start = { 0, 1 };
+    ret1 = functionTester(J, start, 1);
+  }
+
+  double ret2;
+  {
+    // Something random
+    SmallVector start = { 279, -96 };
+    ret2 = functionTester(J, start, 3);
+  }
   assert(std::abs(ret1 - ret2) < 1e-5);
 
-  start[0] = 0;
-  start[1] = 0;
-
-  double const ret3 = functionTester(J, start, 1);
+  double ret3;
+  {
+    SmallVector start = { 0, 0 };
+    ret3 = functionTester(J, start, 1);
+  }
   assert(std::abs(ret1 - ret3) < 1e-5);
 }
diff --git a/src/test-gradient-sample-verysteep.cc b/src/test-gradient-sample-verysteep.cc
index 12fd5c3d..372787ae 100644
--- a/src/test-gradient-sample-verysteep.cc
+++ b/src/test-gradient-sample-verysteep.cc
@@ -19,35 +19,31 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A;
-  A[0][0] = 1;
-  A[0][1] = A[1][0] = 0;
-  A[1][1] = 1;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 2.5;
+  SmallMatrix A = { { 1, 0 }, { 0, 1 } };
+  SmallVector b = { 1, 2.5 };
 
   auto const f = Dune::make_shared<Dune::SampleFunction<100> const>();
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
   Functional J(A, b, phi);
 
-  SmallVector start;
-
-  start[0] = 0;
-  start[1] = 1;
-
-  double const ret1 = functionTester(J, start, 1);
-
-  // Something random
-  start[0] = 279;
-  start[1] = -96;
-
-  double const ret2 = functionTester(J, start, 4);
+  double ret1;
+  {
+    SmallVector start = { 0, 1 };
+    ret1 = functionTester(J, start, 1);
+  }
+
+  double ret2;
+  {
+    // Something random
+    SmallVector start = { 279, -96 };
+    ret2 = functionTester(J, start, 4);
+  }
   assert(std::abs(ret1 - ret2) < 1e-8);
 
-  start[0] = 0;
-  start[1] = 0;
-
-  double const ret3 = functionTester(J, start, 1);
+  double ret3;
+  {
+    SmallVector start = { 0, 0 };
+    ret3 = functionTester(J, start, 1);
+  }
   assert(std::abs(ret1 - ret3) < 1e-5);
 }
diff --git a/src/test-gradient-sample.cc b/src/test-gradient-sample.cc
index e10acc13..c7a8dc5a 100644
--- a/src/test-gradient-sample.cc
+++ b/src/test-gradient-sample.cc
@@ -21,46 +21,43 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A;
-  A[0][0] = 3;
-  A[0][1] = A[1][0] = 1.5;
-  A[1][1] = 4;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 2;
+  SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } };
+  SmallVector b = { 1, 2 };
 
   auto const f = Dune::make_shared<Dune::SampleFunction<2> const>();
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
   Functional J(A, b, phi);
 
-  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))
   */
-  SmallVector analytic_descent;
-  analytic_descent[0] = -(102 - 1 + 2 / sqrt(5));
-  analytic_descent[1] = -(161.5 - 2 + 4 / sqrt(5));
+  SmallVector analytic_descent = { -(102 - 1 + 2 / sqrt(5)),
+                                   -(161.5 - 2 + 4 / sqrt(5)) };
   SmallVector numerical_descent;
-  J.descentDirection(start, numerical_descent);
+  J.descentDirection(SmallVector({ 17, 34 }), numerical_descent);
   assert(two_distance<dim>(analytic_descent, numerical_descent) < 1e-10);
 
-  double const ret1 = functionTester(J, start, 6);
-
-  // Something random
-  start[0] = 279;
-  start[1] = -96;
-
-  double const ret2 = functionTester(J, start, 10);
+  double ret1;
+  {
+    SmallVector start = { 17, 34 };
+    ret1 = functionTester(J, start, 6);
+  }
+
+  double ret2;
+  {
+    // Something random
+    SmallVector start = { 279, -96 };
+    ret2 = functionTester(J, start, 10);
+  }
   assert(std::abs(ret1 - ret2) < 1e-5);
 
-  start[0] = 0;
-  start[1] = 0;
-
-  double const ret3 = functionTester(J, start, 3);
+  double ret3;
+  {
+    SmallVector start = { 0, 0 };
+    ret3 = functionTester(J, start, 3);
+  }
   assert(std::abs(ret1 - ret3) < 1e-5);
 }
diff --git a/src/test-gradient-sample2.cc b/src/test-gradient-sample2.cc
index 9bbd7ec4..ff80966d 100644
--- a/src/test-gradient-sample2.cc
+++ b/src/test-gradient-sample2.cc
@@ -21,32 +21,31 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A;
-  A[0][0] = 1;
-  A[0][1] = A[1][0] = 0;
-  A[1][1] = 1;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 1;
+  SmallMatrix A = { { 1, 0 }, { 0, 1 } };
+  SmallVector b = { 1, 1 };
 
   auto const f = Dune::make_shared<Dune::SampleFunction<2> const>();
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
   Functional J(A, b, phi);
 
-  SmallVector start = b;
-
-  double const ret1 = functionTester(J, start, 2);
-
-  // Something random
-  start[0] = 279;
-  start[1] = -96;
-
-  double const ret2 = functionTester(J, start, 7);
+  double ret1;
+  {
+    SmallVector start = b;
+    ret1 = functionTester(J, start, 2);
+  }
+
+  double ret2;
+  {
+    // Something random
+    SmallVector start = { 279, -96 };
+    ret2 = functionTester(J, start, 7);
+  }
   assert(std::abs(ret1 - ret2) < 1e-5);
 
-  start[0] = 0;
-  start[1] = 0;
-
-  double const ret3 = functionTester(J, start, 2);
+  double ret3;
+  {
+    SmallVector start = { 0, 0 };
+    ret3 = functionTester(J, start, 2);
+  }
   assert(std::abs(ret1 - ret3) < 1e-5);
 }
diff --git a/src/test-gradient-trivial.cc b/src/test-gradient-trivial.cc
index 2718dbe2..6368580f 100644
--- a/src/test-gradient-trivial.cc
+++ b/src/test-gradient-trivial.cc
@@ -20,21 +20,14 @@ int main() {
   typedef Functional::SmallMatrix SmallMatrix;
   typedef Functional::SmallVector SmallVector;
 
-  SmallMatrix A;
-  A[0][0] = 3;
-  A[0][1] = A[1][0] = 1.5;
-  A[1][1] = 4;
-  SmallVector b;
-  b[0] = 1;
-  b[1] = 2;
+  SmallMatrix A = { { 3, 1.5 }, { 1.5, 4 } };
+  SmallVector b = { 1, 2 };
 
   auto const f = Dune::make_shared<Dune::TrivialFunction const>();
   auto const phi = Dune::make_shared<Functional::NonlinearityType const>(f);
   Functional J(A, b, phi);
 
-  SmallVector solution; // Analytic solution
-  solution[0] = 4.0 / 39.0;
-  solution[1] = 6.0 / 13.0;
+  SmallVector solution = { 4.0 / 39.0, 6.0 / 13.0 }; // Analytic solution
 
   double ret1;
   {
@@ -54,9 +47,7 @@ int main() {
   double ret2;
   {
     // Something random
-    SmallVector start;
-    start[0] = 279;
-    start[1] = -96;
+    SmallVector start = { 279, -96 };
 
     SmallVector analytic_descent = b;
     A.mmv(start, analytic_descent);
-- 
GitLab