initial commit of Gregorian/IFC date conversion tools and unit tests

This commit is contained in:
2025-02-16 21:12:54 -08:00
parent 08f09ce109
commit 95985ef032
8 changed files with 339 additions and 0 deletions

95
test_IFCmonths.m Normal file
View File

@@ -0,0 +1,95 @@
classdef test_IFCmonths < matlab.unittest.TestCase
methods(TestClassSetup)
% Shared setup for the entire test class
end
methods(TestMethodSetup)
% Setup for each test
end
methods(Test)
% Test methods
function test_jan1(testCase)
[nMonths, nDays, leaped, yeared] = IFCmonths(1, 2000);
testCase.verifyEqual(nMonths, uint8(1));
testCase.verifyEqual(nDays, uint8(1));
testCase.verifyFalse(leaped);
testCase.verifyFalse(yeared);
end
function test_jan31(testCase)
[nMonths, nDays, leaped, yeared] = IFCmonths(31, 2000);
testCase.verifyEqual(nMonths, uint8(2));
testCase.verifyEqual(nDays, uint8(3));
testCase.verifyFalse(leaped);
testCase.verifyFalse(yeared);
end
function test_jun17_leap(testCase)
[nMonths, nDays, leaped, yeared] = IFCmonths(168, 2000);
testCase.verifyEqual(nMonths, uint8(6));
testCase.verifyEqual(nDays, uint8(28));
testCase.verifyFalse(leaped);
testCase.verifyFalse(yeared);
end
function test_jun17_noleap(testCase)
[nMonths, nDays, leaped, yeared] = IFCmonths(168, 2001);
testCase.verifyEqual(nMonths, uint8(6));
testCase.verifyEqual(nDays, uint8(28));
testCase.verifyFalse(leaped);
testCase.verifyFalse(yeared);
end
function test_jun18_leap(testCase)
[nMonths, nDays, leaped, yeared] = IFCmonths(169, 2000);
testCase.verifyEqual(nMonths, uint8(14));
testCase.verifyEqual(nDays, uint8(0));
testCase.verifyTrue(leaped);
testCase.verifyFalse(yeared);
end
function test_jun18_noleap(testCase)
[nMonths, nDays, leaped, yeared] = IFCmonths(169, 2001);
testCase.verifyEqual(nMonths, uint8(7));
testCase.verifyEqual(nDays, uint8(1));
testCase.verifyFalse(leaped);
testCase.verifyFalse(yeared);
end
function test_dec31_noleap(testCase)
[nMonths, nDays, leaped, yeared] = IFCmonths(365, 2001);
testCase.verifyEqual(nMonths, uint8(14));
testCase.verifyEqual(nDays, uint8(0));
testCase.verifyFalse(leaped);
testCase.verifyTrue(yeared);
end
function test_dec31_leap(testCase)
[nMonths, nDays, leaped, yeared] = IFCmonths(366, 2000);
testCase.verifyEqual(nMonths, uint8(14));
testCase.verifyEqual(nDays, uint8(0));
testCase.verifyTrue(leaped);
testCase.verifyTrue(yeared);
end
function test_today(testCase)
[nMonths, nDays, leaped, yeared] = IFCmonths(363, 2024);
testCase.verifyEqual(nMonths, uint8(13));
testCase.verifyEqual(nDays, uint8(26));
testCase.verifyTrue(leaped);
testCase.verifyFalse(yeared);
end
function test_vectorized(testCase)
[nMonths, nDays, leaped, yeared] = IFCmonths([1; 31; 168; 168; 169; 169; 365; 366; 363], [2000; 2000; 2000; 2001; 2000; 2001; 2001; 2000; 2024]);
testCase.verifyEqual(nMonths, uint8([1; 2; 6; 6; 14; 7; 14; 14; 13]));
testCase.verifyEqual(nDays, uint8([1; 3; 28; 28; 0; 1; 0; 0; 26]));
testCase.verifyEqual(leaped, [false; false; false; false; true; false; false; true; true]);
testCase.verifyEqual(yeared, [false; false; false; false; false; false; true; true; false]);
end
end
end