diff --git a/alan/benches/fill.rs b/alan/benches/fill.rs index 9bdd1bd1..b5745bc1 100644 --- a/alan/benches/fill.rs +++ b/alan/benches/fill.rs @@ -13,7 +13,7 @@ macro_rules! build { macro_rules! run { ( $name:ident ) => { - #[divan::bench(max_time = 60)] + #[divan::bench(max_time = 10)] fn $name() -> Result { Command::new(format!("./{}", stringify!($name))).output() } @@ -54,19 +54,19 @@ run!(t01_fill_100); run!(t02_fill_100_000); run!(t03_fill_100_000_000); -#[divan::bench(max_time = 60)] +#[divan::bench(max_time = 10)] fn t04_vec_100() -> Result<(), std::io::Error> { let v = vec![5; 100]; write("/dev/null", format!("{}", v[0])) } -#[divan::bench(max_time = 60)] +#[divan::bench(max_time = 10)] fn t05_vec_100_000() -> Result<(), std::io::Error> { let v = vec![5; 100_000]; write("/dev/null", format!("{}", v[0])) } -#[divan::bench(max_time = 60)] +#[divan::bench(max_time = 10)] fn t06_vec_100_000_000() -> Result<(), std::io::Error> { let v = vec![5; 100_000_000]; write("/dev/null", format!("{}", v[0])) diff --git a/alan/benches/map.rs b/alan/benches/map.rs index 88c3bba7..c8b6f479 100644 --- a/alan/benches/map.rs +++ b/alan/benches/map.rs @@ -13,7 +13,7 @@ macro_rules! build { macro_rules! run { ( $name:ident ) => { - #[divan::bench(max_time = 60)] + #[divan::bench(max_time = 10)] fn $name() -> Result { Command::new(format!("./{}", stringify!($name))).output() } diff --git a/alan/src/compile/integration_tests.rs b/alan/src/compile/integration_tests.rs index a0937f1f..a98f2ebb 100644 --- a/alan/src/compile/integration_tests.rs +++ b/alan/src/compile/integration_tests.rs @@ -934,90 +934,6 @@ test_full!(array_custom_types => r#" }"#; stdout "2, 4\n"; ); -// Buffers -test_full!(buffer_map => r#" - fn double(x: i64) = x * 2; - export fn main { - const b = Buffer{i64, 3}(1, 2, 3); - b.print; - b.len.print; - b.map(double).print; - b.map(add).print; - }"#; - stdout "[1, 2, 3]\n3\n[2, 4, 6]\n[1, 3, 5]\n"; -); -test_full!(buffer_join => r#" - export fn main { - const b = {string[2]}("Hello", "World!"); - b.join(", ").print; - }"#; - stdout "Hello, World!\n"; -); -test_full!(buffer_reduce => r#" - fn concat(s: string, i: i64) = s.concat(i.string); - export fn main { - const b = {i64[5]}(1, 2, 3, 4, 5); - b.reduce(add).print; - b.reduce("0", concat).print; - }"#; - stdout "15\n012345\n"; -); -test_full!(buffer_has => r#" - fn even(t: i64) = t % 2 == 0; - fn odd(t: i64) = t % 2 == 1; - export fn main { - const test = {i64[6]}(1, 1, 2, 3, 5, 8); - test.has(3).print; - test.has(4).print; - test.has(even).print; - test.has(odd).print; - }"#; - stdout "true\nfalse\ntrue\ntrue\n"; -); -test_full!(buffer_find => r#" - fn odd(x: i64) = x % 2 == 1; - export fn main { - const test = {i64[6]}(1, 1, 2, 3, 5, 8); - test.find(odd).getOr(0).print; - }"#; - stdout "1\n"; -); -test_full!(buffer_every => r#" - fn odd(x: i64) = x % 2 == 1; - - export fn main { - const test = {i64[6]}(1, 1, 2, 3, 5, 8); - test.every(odd).print; - }"#; - stdout "false\n"; -); -test_full!(buffer_concat => r#" - export fn main { - const test = {i64[6]}(1, 1, 2, 3, 5, 8); - const test2 = {i64[3]}(4, 5, 6); - test.concat(test2).map(string).join(', ').print; - }"#; - stdout "1, 1, 2, 3, 5, 8, 4, 5, 6\n"; -); -test_full!(buffer_repeat => r#" - export fn main { - const buf = {i64[3]}(1, 2, 3).repeat(3); - const out = buf.map(string).join(', '); - print(out); - }"#; - stdout "1, 2, 3, 1, 2, 3, 1, 2, 3\n"; -); -test_full!(buffer_store => r#" - export fn main { - let buf = {i64[3]}(1, 2, 5); - print(buf); - buf.store(2, 3).print; - print(buf); - buf[2] = 4; - print(buf); - }"#; - stdout "[1, 2, 5]\n5\n[1, 2, 3]\n[1, 2, 4]\n"; -); // Hashing test!(hash => r#" diff --git a/alan/test.ln b/alan/test.ln index 0f2e5e11..b4efeaf3 100644 --- a/alan/test.ln +++ b/alan/test.ln @@ -680,5 +680,59 @@ export fn{Test} main { test.assert(eq, arr.map(string).join(', '), '1, 2, 3, 4'); }); + test.describe("Buffers") + .it("join", fn (test: Mut{Testing}) { + const b = {string[2]}("Hello", "World!"); + test.assert(eq, b.join(", "), "Hello, World!"); + }) + .it("map", fn (test: Mut{Testing}) { + const b = Buffer{i64, 3}(1, 2, 3); + test + .assert(eq, b.map(string).join(", "), '1, 2, 3') + .assert(eq, b.len, 3) + .assert(eq, b.map(fn double(x: i64) = x * 2).map(string).join(', '), '2, 4, 6') + .assert(eq, b.map(add).map(string).join(', '), '1, 3, 5'); + }) + .it("reduce", fn (test: Mut{Testing}) { + const b = {i64[5]}(1, 2, 3, 4, 5); + test + .assert(eq, b.reduce(add)!!, 15) // TODO: We can probably get rid of the Fallible here + .assert(eq, b.map(string).reduce("0", concat), "012345"); + }) + .it("has", fn (test: Mut{Testing}) { + const b = {i64[6]}(1, 1, 2, 3, 5, 8); + test + .assert(eq, b.has(3), true) + .assert(eq, b.has(4), false) + .assert(eq, b.has(fn (i: i64) = i % 2 == 0), true) + .assert(eq, b.has(fn (i: i64) = i % 2 == 1), true); + }) + .it("find", fn (test: Mut{Testing}) { + const b = {i64[6]}(1, 1, 2, 3, 5, 8); + test.assert(eq, b.find(fn (i: i64) = i % 2 == 1) ?? 0, 1); + }) + .it("every", fn (test: Mut{Testing}) { + const b = {i64[6]}(1, 1, 2, 3, 5, 8); + test.assert(eq, b.every(fn (i: i64) = i % 2 == 1), false); + }) + .it("concat", fn (test: Mut{Testing}) { + const b = {i64[6]}(1, 1, 2, 3, 5, 8); + const c = {i64[3]}(4, 5, 6); + test.assert(eq, b.concat(c).map(string).join(', '), '1, 1, 2, 3, 5, 8, 4, 5, 6'); + }) + .it("repeat", fn (test: Mut{Testing}) { + const b = {i64[3]}(1, 2, 3).repeat(3); + test.assert(eq, b.map(string).join(', '), '1, 2, 3, 1, 2, 3, 1, 2, 3'); + }) + .it('store', fn (test: Mut{Testing}) { + let b = {i64[3]}(1, 2, 5); + test + .assert(eq, b.map(string).join(', '), '1, 2, 5') + .assert(eq, b.store(2, 3)!!, 5) + .assert(eq, b.map(string).join(', '), '1, 2, 3'); + b[2] = 4; + test.assert(eq, b.map(string).join(', '), '1, 2, 4'); + }); + test.report; } \ No newline at end of file