fix(v1.0.2): Array grow from 0, Map/Set rehash, checked div/mod
ci / build (ubuntu) (push) Has been cancelled
ci / macos smoke (push) Has been cancelled
ci / windows smoke (push) Has been cancelled
selfhost-loop / bootstrap determinism (push) Has been cancelled
ci / unit + fmt (push) Has been cancelled
ci / examples (push) Has been cancelled
ci / goldens + tools (push) Has been cancelled
ci / apps (push) Has been cancelled
ci / selfhost smoke (push) Has been cancelled
ci / CI gate (push) Has been cancelled
ci / build (ubuntu) (push) Has been cancelled
ci / macos smoke (push) Has been cancelled
ci / windows smoke (push) Has been cancelled
selfhost-loop / bootstrap determinism (push) Has been cancelled
ci / unit + fmt (push) Has been cancelled
ci / examples (push) Has been cancelled
ci / goldens + tools (push) Has been cancelled
ci / apps (push) Has been cancelled
ci / selfhost smoke (push) Has been cancelled
ci / CI gate (push) Has been cancelled
- Array_Push grows from cap 0 (same min as Insert) to avoid segfault - Map/StringMap/Set: default min cap 8 and auto-rehash at ~50% load - Integer / and % emit bux_div_i64 / bux_mod_i64 (panic instead of SIGFPE) - Bump version to 1.0.2; stdlib golden regressions; fmt clean
This commit is contained in:
@@ -11,6 +11,15 @@ import Std::Test::{
|
||||
};
|
||||
|
||||
func Main() -> int {
|
||||
// Zero-capacity grow (v1.0.2): must not segfault
|
||||
var z: Array<int> = Array_New<int>(0);
|
||||
Array_Push<int>(&z, 7);
|
||||
Array_Push<int>(&z, 8);
|
||||
Test_AssertEqInt(Array_Len<int>(&z) as int, 2);
|
||||
Test_AssertEqInt(Array_Get<int>(&z, 0), 7);
|
||||
Test_AssertEqInt(Array_Get<int>(&z, 1), 8);
|
||||
Array_Free<int>(&z);
|
||||
|
||||
var arr: Array<int> = Array_New<int>(2);
|
||||
Array_Reserve<int>(&arr, 8);
|
||||
Test_AssertTrue(Array_Cap<int>(&arr) >= 8);
|
||||
|
||||
@@ -34,6 +34,23 @@ func Main() -> int {
|
||||
Test_AssertTrue(Map_IsEmpty<int, int>(&m));
|
||||
Map_Free<int, int>(&m);
|
||||
|
||||
// Auto-grow past initial cap (v1.0.2): must not hang
|
||||
var tiny: Map<int, int> = Map_New<int, int>(2);
|
||||
Map_Set<int, int>(&tiny, 1, 10);
|
||||
Map_Set<int, int>(&tiny, 2, 20);
|
||||
Map_Set<int, int>(&tiny, 3, 30);
|
||||
Map_Set<int, int>(&tiny, 4, 40);
|
||||
Map_Set<int, int>(&tiny, 5, 50);
|
||||
Test_AssertEqInt(Map_Len<int, int>(&tiny) as int, 5);
|
||||
Test_AssertEqInt(Map_Get<int, int>(&tiny, 5), 50);
|
||||
Map_Free<int, int>(&tiny);
|
||||
|
||||
// Zero-cap request defaults to usable table (v1.0.2)
|
||||
var z: Map<int, int> = Map_New<int, int>(0);
|
||||
Map_Set<int, int>(&z, 9, 99);
|
||||
Test_AssertEqInt(Map_Get<int, int>(&z, 9), 99);
|
||||
Map_Free<int, int>(&z);
|
||||
|
||||
var s: Set<int> = Set_New<int>(16);
|
||||
Set_Add<int>(&s, 10);
|
||||
Set_Add<int>(&s, 20);
|
||||
@@ -45,6 +62,16 @@ func Main() -> int {
|
||||
Test_AssertFalse(Set_IsEmpty<int>(&s));
|
||||
Set_Free<int>(&s);
|
||||
|
||||
// Set grow (v1.0.2)
|
||||
var s2: Set<int> = Set_New<int>(2);
|
||||
Set_Add<int>(&s2, 1);
|
||||
Set_Add<int>(&s2, 2);
|
||||
Set_Add<int>(&s2, 3);
|
||||
Set_Add<int>(&s2, 4);
|
||||
Test_AssertEqInt(Set_Len<int>(&s2) as int, 4);
|
||||
Test_AssertTrue(Set_Has<int>(&s2, 4));
|
||||
Set_Free<int>(&s2);
|
||||
|
||||
let ok: Result<int, String> = Result_NewOk<int, String>(42);
|
||||
let err: Result<int, String> = Result_NewErr<int, String>("boom");
|
||||
Test_AssertTrue(Result_IsOk<int, String>(ok));
|
||||
|
||||
Reference in New Issue
Block a user