Adds a testsuite to Time API.

This commit is contained in:
zontreck 2024-05-23 17:25:14 -07:00
parent 6ba00044af
commit d4a6a3609e
2 changed files with 35 additions and 0 deletions

View file

@ -1,3 +1,5 @@
import 'package:libac_flutter/nbt/Stream.dart';
class Time {
int hours;
int minutes;
@ -119,4 +121,14 @@ class Time {
return Time(hours: hours, minutes: minutes, seconds: seconds);
}
@override
String toString() {
StringBuilder builder = StringBuilder();
if (hours > 0) builder.append("${hours}h");
if (minutes > 0) builder.append("${minutes}m");
if (seconds > 0) builder.append("${seconds}s");
return "${builder}";
}
}

23
test/time_test.dart Normal file
View file

@ -0,0 +1,23 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:libac_flutter/utils/TimeUtils.dart';
void main() {
test("Parse time notation", () {
Time time = Time.fromNotation("4h9s");
expect(time.toString(), "4h9s");
expect(time.hours, 4);
expect(time.minutes, 0);
expect(time.seconds, 9);
});
test("Add time", () {
// Depends on first test working!
Time time = Time.fromNotation("4h9s");
time.add(Time(hours: 0, minutes: 80, seconds: 1));
expect(time.hours, 5);
expect(time.minutes, 20);
expect(time.seconds, 10);
});
}