So, I'm doing a very simple project for a command line chess move generator which takes input from the command line in the form of a list of pieces and generates the possible moves for a given piece. For this project the goal is to have as close to 100% line coverage as possible.
Question 1:
I have the following for taking input from the command line in the form "Rf1, Kg1, Pf2, Ph2, Pg3" (color is specified by prompt):
mod command_line_input {
use std::io;
pub fn get_input(prompt: &str) -> String{
println!("{}",prompt);
let mut input = String::new();
match io::stdin().read_line(&mut input) {
Ok(_goes_into_input_above) => {},
Err(_no_updates_is_fine) => {},
}
input.trim().to_string()
}
}
which I am completely unsure of how to properly test.
Question 2:
Additionally, I have the following Struct and implementation:
#[derive(Copy, Clone, Debug)]
struct ChessPiece {
color: bool, // white = false; black = true
name: char, // K, Q, R, B, N, and P to identify the King, Queen, Rook, Bishop, Knight, and Pawn respectively
x_position: u8, // a = 1, ..., h = 8
y_position: u8, // [1, 8]
}
impl ChessPiece {
pub fn new(color: bool, piece_input: &str) -> Self {
let piece = Self { color,
name: piece_input.chars().nth(0).unwrap(),
x_position: grid_char_to_grid_number_letter(piece_input.chars().nth(1).unwrap()),
y_position: grid_char_to_grid_number_number(piece_input.chars().nth(2).unwrap())
};
piece
}
}
with the following test:
#[test]
fn test_piece_new() {
let white_king_a_1 = ChessPiece {color:false, name: 'K', x_position: 1 as u8, y_position: 1 as u8};
let king_a_1_str = "Ka1";
let parsed_piece = ChessPiece::new(false, king_a_1_str);
assert_eq!(parsed_piece.color, white_king_a_1.color);
assert_eq!(parsed_piece.name, white_king_a_1.name);
assert_eq!(parsed_piece.x_position, white_king_a_1.x_position);
assert_eq!(parsed_piece.y_position, white_king_a_1.y_position);
I am using the code coverage tool in Jetbrains CLion and it reports that the implementation
part of the struct is covered, but the definition of the struct is not. How do I remedy this?
Question 3:
Is there a more strict than standard setting for cargo? I understand it already does a decent amount of static analysis during compilation, but I'm looking to have as much analysis done as is reasonable.
Thanks in advance!
Edit: Should this be here or in "Code Review"?