-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/experiments1' into develop
- Loading branch information
Showing
5 changed files
with
423 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.