A simple, small calculator placed discreetly near the Windows Taskbar or anywhere on the screen
0

Configure Feed

Select the types of activity you want to include in your feed.

test: add calc engine harness and arithmetic characterization tests

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Marco Maroni (Jul 14, 2026, 2:59 PM +0200) 689ca8aa c5cc7d9f

+104
+2
.gitignore
··· 194 194 # Visual Studio / MSBuild (Windows 11 migration) 195 195 .vs/ 196 196 Generated Files/ 197 + tests/*.exe 198 + tests/*.obj 197 199 *.appx 198 200 *.msix 199 201 *.appxbundle
+65
tests/CalcTests.cpp
··· 1 + #include <windows.h> 2 + #include <tchar.h> 3 + #include "../Calculator.h" 4 + #include "TestHarness.h" 5 + 6 + // Feed a sequence of command chars through the engine, threading the 7 + // output string back in as the next input (as the UI does). 8 + static void feed(calc& c, const wchar_t* keys, wchar_t* out) { 9 + wcscpy(out, L"0"); 10 + wchar_t in[1024]; 11 + for (const wchar_t* p = keys; *p; ++p) { 12 + wcscpy(in, out); 13 + c.change_state(*p, in, out); 14 + } 15 + } 16 + 17 + TEST(add) { 18 + calc c; c.set_precision(2); 19 + wchar_t out[1024]; 20 + feed(c, L"2+3=", out); 21 + EXPECT_WSTR(out, L"5"); 22 + return true; 23 + } 24 + 25 + TEST(subtract) { 26 + calc c; c.set_precision(2); 27 + wchar_t out[1024]; 28 + feed(c, L"7-2=", out); 29 + EXPECT_WSTR(out, L"5"); 30 + return true; 31 + } 32 + 33 + TEST(multiply) { 34 + calc c; c.set_precision(2); 35 + wchar_t out[1024]; 36 + feed(c, L"6*7=", out); 37 + EXPECT_WSTR(out, L"42"); 38 + return true; 39 + } 40 + 41 + TEST(divide) { 42 + calc c; c.set_precision(2); 43 + wchar_t out[1024]; 44 + feed(c, L"8/2=", out); 45 + EXPECT_WSTR(out, L"4"); 46 + return true; 47 + } 48 + 49 + TEST(decimal_and_add) { 50 + calc c; c.set_precision(2); 51 + wchar_t out[1024]; 52 + feed(c, L"1.5+1.5=", out); 53 + EXPECT_WSTR(out, L"3"); 54 + return true; 55 + } 56 + 57 + TEST(chained_operations) { 58 + calc c; c.set_precision(2); 59 + wchar_t out[1024]; 60 + feed(c, L"2+3+4=", out); 61 + EXPECT_WSTR(out, L"9"); 62 + return true; 63 + } 64 + 65 + int wmain() { return run_all(); }
+31
tests/TestHarness.h
··· 1 + #pragma once 2 + #include <cstdio> 3 + #include <cwchar> 4 + #include <vector> 5 + #include <functional> 6 + 7 + struct TestCase { const char* name; std::function<bool()> fn; }; 8 + inline std::vector<TestCase>& registry() { static std::vector<TestCase> r; return r; } 9 + struct Registrar { Registrar(const char* n, std::function<bool()> f) { registry().push_back({ n, f }); } }; 10 + 11 + #define TEST(name) \ 12 + static bool name(); \ 13 + static Registrar reg_##name(#name, name); \ 14 + static bool name() 15 + 16 + #define EXPECT_WSTR(actual, expected) do { \ 17 + if (wcscmp((actual), (expected)) != 0) { \ 18 + wprintf(L" expected [%s] got [%s]\n", (expected), (actual)); return false; } \ 19 + } while(0) 20 + 21 + inline int run_all() { 22 + int failed = 0; 23 + for (auto& tc : registry()) { 24 + bool ok = false; 25 + try { ok = tc.fn(); } catch (...) { ok = false; } 26 + printf("[%s] %s\n", ok ? "PASS" : "FAIL", tc.name); 27 + if (!ok) failed++; 28 + } 29 + printf("\n%d/%d passed\n", (int)registry().size() - failed, (int)registry().size()); 30 + return failed ? 1 : 0; 31 + }
+6
tests/build-and-run.cmd
··· 1 + @echo off 2 + setlocal 3 + cd /d "%~dp0" 4 + cl /nologo /EHsc /std:c++17 /DUNICODE /D_UNICODE /I.. /Fe:CalcTests.exe CalcTests.cpp ..\Calculator.cpp 5 + if errorlevel 1 exit /b 1 6 + ".\CalcTests.exe"