summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CLI/rust/src/game_of_life/generators/input.rs27
1 files changed, 14 insertions, 13 deletions
diff --git a/CLI/rust/src/game_of_life/generators/input.rs b/CLI/rust/src/game_of_life/generators/input.rs
index 4f205cb..9584cee 100644
--- a/CLI/rust/src/game_of_life/generators/input.rs
+++ b/CLI/rust/src/game_of_life/generators/input.rs
@@ -78,16 +78,7 @@ fn generate_file_data(opts: Opts) -> Result<Universe, Error> {
))
}
};
- let data: Vec<Vec<bool>> = file
- .split("\n")
- .map(|s| {
- s.to_string()
- .chars()
- .map(|c| c.is_ascii_alphanumeric())
- .collect()
- })
- .collect();
- Ok(populate(opts, data))
+ Ok(populate(opts, file))
}
#[cfg(test)]
@@ -148,8 +139,18 @@ fn generate_url_data(_opts: Opts) -> Result<Universe, Error> {
/// Return a universe struct with populated data from the data param
///
/// The data param is reshaped to fit with the opts width/height (extended or shrinked)
-fn populate(opts: Opts, data: Vec<Vec<bool>>) -> Universe {
+fn populate(opts: Opts, raw_data: String) -> Universe {
let (width, height) = (opts.width as usize, opts.height as usize);
+ let data: Vec<Vec<bool>> = raw_data
+ .split("\n")
+ .map(|s| {
+ s.to_string()
+ .chars()
+ .map(|c| c.is_ascii_alphanumeric())
+ .collect()
+ })
+ .collect();
+
let mut current = vec![vec![false; width]; height];
for i in 0..height {
@@ -188,7 +189,7 @@ mod populate {
#[test]
fn expand_data() {
- let data = vec![vec![true, false, true]; 3];
+ let data = String::from("x.x\nO.0\nO.X");
let opts = opts(5, 5);
let universe = populate(opts.clone(), data);
@@ -210,7 +211,7 @@ mod populate {
#[test]
fn shrink_data() {
- let data = vec![vec![true, false, true]; 3];
+ let data = String::from("x.x\nO.0\nO.X");
let opts = opts(2, 2);
let universe = populate(opts.clone(), data);