From 2e16b8877e2d4877be69e6107eaeb144c5429242 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Sat, 21 Oct 2017 19:58:32 +0100 Subject: [PATCH] add unit tests for Note.oct and String.asNote This should serve as a starting point for other unit tests. --- wslib-tests/TestExtVariousAsNote.sc | 29 +++++++++++++++++++++++++++++ wslib-tests/TestNote.sc | 25 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 wslib-tests/TestExtVariousAsNote.sc create mode 100644 wslib-tests/TestNote.sc diff --git a/wslib-tests/TestExtVariousAsNote.sc b/wslib-tests/TestExtVariousAsNote.sc new file mode 100644 index 0000000..b3ea729 --- /dev/null +++ b/wslib-tests/TestExtVariousAsNote.sc @@ -0,0 +1,29 @@ +TestStringExtVariousAsNote : UnitTest { + setUp { + } + + tearDown { + } + + test_asNote { + [ + ["B1", 47], + ["C2", 48], + ["C#2", 49], + ["B2", 59], + ["C3", 60], + ["C#3", 61], + ["B3", 71], + ].do { |pair| + var in = pair[0], expected = pair[1]; + var got = in.asNote; + this.assertEquals(got.class, Note); + this.assertEquals(got.midi, expected); + }; + } +} + +// To test, use one of the following approaches: +// +// UnitTest.gui; +// UnitTest.runTest("TestExtVariousAsNote:test_asNote"); diff --git a/wslib-tests/TestNote.sc b/wslib-tests/TestNote.sc new file mode 100644 index 0000000..93ddcba --- /dev/null +++ b/wslib-tests/TestNote.sc @@ -0,0 +1,25 @@ +TestNote : UnitTest { + setUp { + } + + tearDown { + } + + test_oct { + [ + ["C3", 3], + ["Cb3", 2], + ["B#4", 5], + ].do { |pair| + var in = pair[0], expected = pair[1]; + var got = in.asNote; + this.assertEquals(got.oct, expected); + }; + } +} + +// To test, use one of the following approaches: +// +// UnitTest.gui; +// UnitTest.runTestClassForClass(Note); +// UnitTest.runTest("TestNote:test_oct");