61 lines
1.9 KiB
C++
61 lines
1.9 KiB
C++
/*
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
* Test the string formatting functions.
|
|
*/
|
|
#include <core/string.h>
|
|
#include <tests/test.h>
|
|
|
|
void test_utos()
|
|
{
|
|
test_equal(string :: utos(0), "0");
|
|
test_equal(string :: utos(1), "1");
|
|
test_equal(string :: utos(42), "42");
|
|
test_equal(string :: utos(999), "999");
|
|
}
|
|
|
|
void test_sec2str()
|
|
{
|
|
test_equal(string :: sec2str(0), "0:00");
|
|
test_equal(string :: sec2str(5), "0:05");
|
|
test_equal(string :: sec2str(10), "0:10");
|
|
test_equal(string :: sec2str(60), "1:00");
|
|
test_equal(string :: sec2str(65), "1:05");
|
|
test_equal(string :: sec2str(75), "1:15");
|
|
test_equal(string :: sec2str(600), "10:00");
|
|
test_equal(string :: sec2str(605), "10:05");
|
|
test_equal(string :: sec2str(615), "10:15");
|
|
test_equal(string :: sec2str(660), "11:00");
|
|
test_equal(string :: sec2str(665), "11:05");
|
|
test_equal(string :: sec2str(675), "11:15");
|
|
}
|
|
|
|
void test_sec2str_detailed()
|
|
{
|
|
|
|
unsigned int minute = 60;
|
|
unsigned int hour = 3600;
|
|
unsigned int day = 86400;
|
|
|
|
test_equal(string :: sec2str_detailed(day), "1 day");
|
|
test_equal(string :: sec2str_detailed(2 * day), "2 days");
|
|
|
|
test_equal(string :: sec2str_detailed(day + hour), "1 day, 1 hour");
|
|
test_equal(string :: sec2str_detailed(hour), "1 hour");
|
|
test_equal(string :: sec2str_detailed(2 * hour), "2 hours");
|
|
|
|
test_equal(string :: sec2str_detailed(hour + minute), "1 hour, 1 minute");
|
|
test_equal(string :: sec2str_detailed(minute), "1 minute");
|
|
test_equal(string :: sec2str_detailed(2 * minute), "2 minutes");
|
|
|
|
test_equal(string :: sec2str_detailed(minute + 1), "1 minute, 1 second");
|
|
test_equal(string :: sec2str_detailed(1), "1 second");
|
|
test_equal(string :: sec2str_detailed(2), "2 seconds");
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
test :: run("Unsigned to String Test", test_utos);
|
|
test :: run("Seconds to String Test", test_sec2str);
|
|
test :: run("Seconds to String (Detailed) Test", test_sec2str_detailed);
|
|
}
|