summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2020-04-20 00:14:45 +0200
committerAndré Nusser <andre.nusser@googlemail.com>2020-04-20 00:14:45 +0200
commit291149306dd3920e810ed22ca87bc055176781ed (patch)
treefc0a98621faa4500d02a551702f5ff05570897fe
parentfc8a6632d515fa36aa14e95bb1bbde57a10fd43a (diff)
Add stub for unit test and fix a bug in Powermap.
-rw-r--r--src/powermap.cc3
-rw-r--r--test/Makefile.am11
-rw-r--r--test/powermaptest.cc54
3 files changed, 66 insertions, 2 deletions
diff --git a/src/powermap.cc b/src/powermap.cc
index 00365af..a400cf9 100644
--- a/src/powermap.cc
+++ b/src/powermap.cc
@@ -48,7 +48,7 @@ Power computeValue(
auto const y0 = P0.out;
auto const y1 = P1.out;
auto const dx = x1 - x0;
- auto const x_prime = (x - x1)/dx;
+ auto const x_prime = (x - x0)/dx;
return h00(x_prime)*y0 + h10(x_prime)*dx*m0 + h01(x_prime)*y1 + h11(x_prime)*dx*m1;
}
@@ -131,6 +131,7 @@ void Powermap::updateSpline()
assert(0. <= fixed[0].out && fixed[0].out <= fixed[1].out &&
fixed[1].out <= fixed[2].out && fixed[2].out <= 1.);
+ // TODO: What to do if fixed[0] is (0,0) or fixed[2] is (1,1)??
Powers X = shelf ? Powers{fixed[0].in, fixed[1].in, fixed[2].in}
: Powers{0., fixed[0].in, fixed[1].in, fixed[2].in, 1.};
Powers P = shelf ? Powers{fixed[0].out, fixed[1].out, fixed[2].out}
diff --git a/test/Makefile.am b/test/Makefile.am
index 8332cbe..b0c0149 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -8,7 +8,7 @@ TESTS = resource enginetest paintertest configfile audiocache \
randomtest atomictest syncedsettingstest imagecachetest \
semaphoretest drumkitcreatortest bytesizeparsertest notifiertest \
dgxmlparsertest domloadertest configparsertest midimapparsertest \
- eventsdstest
+ eventsdstest powermaptest
EXTRA_DIST = \
dgunit.h \
@@ -270,4 +270,13 @@ eventsdstest_SOURCES = \
eventsdstest.cc \
dgtest.cc
+powermaptest_CXXFLAGS = -DOUTPUT=\"powermaptest\" \
+ $(DEBUG_FLAGS) \
+ -I$(top_srcdir)/src
+powermaptest_LDFLAGS =
+powermaptest_SOURCES = \
+ $(top_srcdir)/src/powermap.cc \
+ powermaptest.cc \
+ dgtest.cc
+
endif
diff --git a/test/powermaptest.cc b/test/powermaptest.cc
new file mode 100644
index 0000000..18af707
--- /dev/null
+++ b/test/powermaptest.cc
@@ -0,0 +1,54 @@
+/* -*- Mode: c++ -*- */
+/***************************************************************************
+ * powermaptest.cc
+ *
+ * Sun Apr 19 23:23:37 CEST 2020
+ * Copyright 2020 André Nusser
+ * andre.nusser@googlemail.com
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "dgunit.h"
+
+#include "../src/powermap.h"
+
+// FIXME:
+#include <iostream>
+
+class test_powermaptest
+ : public DGUnit
+{
+public:
+ test_powermaptest()
+ {
+ DGUNIT_TEST(test_powermaptest::check_values);
+ }
+
+ void check_values()
+ {
+ Powermap powermap;
+
+ // FIXME
+ std::cout << powermap.map(.8) << std::endl;
+ DGUNIT_ASSERT_EQUAL(powermap.map(.8), .8);
+ }
+};
+
+// Registers the fixture into the 'registry'
+static test_powermaptest test;