Skip to content

Commit

Permalink
Merge branch 'feature/experiments1' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
neoneye committed Feb 6, 2024
2 parents 3ec7ecc + 0bcb7aa commit ca164de
Show file tree
Hide file tree
Showing 5 changed files with 423 additions and 33 deletions.
2 changes: 1 addition & 1 deletion rust_project/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust_project/loda-rust-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "loda-rust-cli"
version = "2024.1.6"
version = "2024.2.6"
authors = ["Simon Strandgaard <[email protected]>"]
description = "Command line interface for LODA Rust"
repository = "https://github.com/loda-lang/loda-rust"
Expand Down
44 changes: 44 additions & 0 deletions rust_project/loda-rust-cli/src/arc/checkerboard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use super::{Image, ImageTryCreate};
use num_integer::Integer;

#[allow(dead_code)]
pub struct Checkerboard;

impl Checkerboard {
#[allow(dead_code)]
pub fn checkerboard(width: u8, height: u8, color0: u8, color1: u8) -> Image {
if width == 0 || height == 0 {
return Image::empty();
}
let mut pixels = Vec::<u8>::new();
for y in 0..(height as u16) {
for x in 0..(width as u16) {
let color = if (x + y).is_even() { color0 } else { color1 };
pixels.push(color);
}
}
assert_eq!(pixels.len(), (width as usize) * (height as usize));
Image::try_create(width, height, pixels).expect("image")
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_10000_checkerboard() {
// Act
let actual: Image = Checkerboard::checkerboard(5, 4, 0, 1);

// Assert
let expected_pixels: Vec<u8> = vec![
0, 1, 0, 1, 0,
1, 0, 1, 0, 1,
0, 1, 0, 1, 0,
1, 0, 1, 0, 1,
];
let expected: Image = Image::try_create(5, 4, expected_pixels).expect("image");
assert_eq!(actual, expected);
}
}
Loading

0 comments on commit ca164de

Please sign in to comment.