LibAC-dart/test/uuid_test.dart
2024-07-08 22:25:54 -07:00

64 lines
1.6 KiB
Dart

import 'package:libac_dart/nbt/Stream.dart';
import 'package:libac_dart/utils/uuid/UUID.dart';
import 'package:test/expect.dart';
import 'package:test/scaffolding.dart';
void main() {
test("Store a 64bit value in int", () {
int X = 9223372036854775807;
expect(X.toString(), "9223372036854775807");
});
test("Generate a UUID v4", () {
var ID = UUID.generate(4);
expect(UUID.validate(ID.toString()), true);
});
test("Generate 10 UUIDv4", () {
List<UUID> ID = [];
for (int i = 0; i < 10; i++) {
ID.add(UUID.generate(4));
}
for (UUID sID in ID) {
print("ID : $sID}");
}
});
test("Test stream bitflipping", () {
ByteLayer layer = ByteLayer();
layer.writeBytes({0, 255, 80});
layer.setBit(0, 0x10);
layer.unsetSetBit(1, 0x0F, 0x50);
expect(layer.checkBit(0, 0x10), true);
expect(layer.checkBit(1, 0x50), true);
expect(layer.getBit(2), 80);
});
test("Test v3 implementation", () {
var expected =
"3e1b8c8a-efab-381b-ab57-4764c45b0889"; // Minecraft offline UUID : zontreck
var ID3 = UUID.generate(3, parameters: ["OfflinePlayer:zontreck", ""]);
expect(ID3.toString(), expected);
});
test("Parse a v3 and compare", () {
var asString = "3e1b8c8a-efab-381b-ab57-4764c45b0889";
var ID3 = UUID.parse(asString);
var ID3X = UUID.generate(3, parameters: ["OfflinePlayer:zontreck", ""]);
//expect(ID3.MSB, ID3X.MSB);
//expect(ID3.LSB, ID3X.LSB);
expect(ID3.toString(), asString);
});
test("Null UUID", () {
var expected = "00000000-0000-0000-0000-000000000000";
var actual = UUID.ZERO.toString();
expect(actual, expected);
});
}