This commit is contained in:
2025-03-25 13:49:02 +01:00
parent 44e26460d8
commit d2bb65a91e
12 changed files with 546 additions and 6 deletions
+51
View File
@@ -0,0 +1,51 @@
import "package:arcane_helper_utils/arcane_helper_utils.dart";
import "package:test/test.dart";
void main() {
group("DoubleConverter", () {
const converter = DoubleConverter();
test("fromJson converts valid string to double", () {
expect(converter.fromJson("123.45"), 123.45);
expect(converter.fromJson("-123.45"), -123.45);
expect(converter.fromJson("0.0"), 0.0);
});
test("fromJson handles null and invalid inputs", () {
expect(converter.fromJson(null), null);
expect(converter.fromJson(""), null);
expect(converter.fromJson("invalid"), null);
});
test("toJson converts double to string", () {
expect(converter.toJson(123.45), "123.45");
expect(converter.toJson(-123.45), "-123.45");
expect(converter.toJson(0.0), "0.0");
expect(converter.toJson(null), null);
});
});
group("IntegerConverter", () {
const converter = IntegerConverter();
test("fromJson converts valid string to int", () {
expect(converter.fromJson("123"), 123);
expect(converter.fromJson("-123"), -123);
expect(converter.fromJson("0"), 0);
});
test("fromJson handles null and invalid inputs", () {
expect(converter.fromJson(null), null);
expect(converter.fromJson(""), null);
expect(converter.fromJson("invalid"), null);
expect(converter.fromJson("123.45"), null);
});
test("toJson converts int to string", () {
expect(converter.toJson(123), "123");
expect(converter.toJson(-123), "-123");
expect(converter.toJson(0), "0");
expect(converter.toJson(null), null);
});
});
}
+71
View File
@@ -0,0 +1,71 @@
import "package:arcane_helper_utils/arcane_helper_utils.dart";
import "package:test/test.dart";
void main() {
group("Ticker", () {
test("no ticks emitted when interval is null and timeout is less than 1s",
() async {
const ticker = Ticker();
final stream = ticker.tick(
timeout: const Duration(milliseconds: 300),
);
final List<int> emitted = await stream.toList();
expect(emitted, isEmpty);
});
test("one tick emitted when interval is null and timeout is 1s", () async {
const ticker = Ticker();
final stream = ticker.tick(
timeout: const Duration(seconds: 1),
);
final List<int> emitted = await stream.toList();
expect(emitted, [0]);
});
test("multiple ticks emitted when interval is null and timeout >1s",
() async {
const ticker = Ticker();
final stream = ticker.tick(
timeout: const Duration(seconds: 3),
);
final List<int> emitted = await stream.toList();
expect(emitted, [2, 1, 0]);
});
test("respects custom interval", () async {
const ticker = Ticker();
final stream = ticker.tick(
timeout: const Duration(milliseconds: 400),
interval: const Duration(milliseconds: 200),
);
final List<int> emitted = await stream.toList();
expect(emitted, [1, 0]);
});
test("handles zero timeout", () async {
const ticker = Ticker();
final stream = ticker.tick(
timeout: Duration.zero,
interval: const Duration(seconds: 1),
);
final List<int> emitted = await stream.toList();
expect(emitted, isEmpty);
});
test("handles timeout less than interval", () async {
const ticker = Ticker();
final stream = ticker.tick(
timeout: const Duration(milliseconds: 500),
interval: const Duration(seconds: 1),
);
final List<int> emitted = await stream.toList();
expect(emitted, isEmpty);
});
});
}