Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert the buffer tests to the new test harness #970

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions alan/benches/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output, std::io::Error> {
Command::new(format!("./{}", stringify!($name))).output()
}
Expand Down Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion alan/benches/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output, std::io::Error> {
Command::new(format!("./{}", stringify!($name))).output()
}
Expand Down
84 changes: 0 additions & 84 deletions alan/src/compile/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand Down
54 changes: 54 additions & 0 deletions alan/test.ln
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading