Test: First failing test finished

This commit is contained in:
Jonas Zeunert
2024-02-17 18:33:49 +01:00
parent 31bc601dfd
commit c53258721f

View File

@@ -1,4 +1,4 @@
use clap::{Parser, Subcommand};
use clap::Parser;
#[derive(Parser)]
#[command(version, about, long_about = None)]
@@ -7,21 +7,58 @@ struct Cli {
// absense
field: String,
// Size of one size of the field. For standard 3x3 input 3 (default)
// Size of one size of the field. For standard 9x9 input 9 (default)
#[arg(short, long)]
field_size: u16,
field_size: usize,
}
#[derive(PartialEq, Debug)]
struct Playfield {
fields: [[Field; 9]; 9],
fields: Vec<Vec<Field>>,
open_fields: Vec<u8>,
}
#[derive(Clone, PartialEq, Debug)]
struct Field {
possible_values: [u8; 9],
possible_values: Vec<u8>,
value: Option<u8>,
}
impl Playfield {
fn new(size: usize) -> Playfield {
let fields = vec![
vec![
Field {
possible_values: Vec::<u8>::new(),
value: None
};
size
];
size
];
let open_fields = Vec::<u8>::new();
Self {
fields,
open_fields,
}
}
}
impl Field {
fn new(value: u8) -> Field {
Self {
possible_values: Vec::<u8>::new(),
value: Some(value),
}
}
fn default() -> Field {
Self {
possible_values: Vec::<u8>::new(),
value: None,
}
}
}
fn main() {
let cli = Cli::parse();
@@ -30,7 +67,9 @@ fn main() {
println!("Hello, world!");
}
fn parse_playfield(field: &String, field_size: u16) -> Playfield {}
fn parse_playfield(field: &String, field_size: usize) -> Playfield {
Playfield::new(field_size)
}
#[cfg(test)]
mod tests {
@@ -38,9 +77,21 @@ mod tests {
#[test]
fn test_parse_field() {
let input = "1 2 3 0 0 0 1 2 3";
let input = "1 2 3 0 0 0 3 2 1";
let field_size = 2;
let playfield = parse_playfield(&input.to_string(), field_size);
assert_eq!(
playfield,
Playfield {
fields: vec![
vec![Field::new(1), Field::new(2), Field::new(3)],
vec![Field::default(), Field::default(), Field::default()],
vec![Field::new(3), Field::new(2), Field::new(1)]
],
open_fields: vec![]
}
)
}
}