1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#![cfg(not(doctest))]
#![doc = include_str!("../README.md")]

pub mod chess_board;
pub mod chess_piece;

pub use chess_board::{coordinates, fen_notation, notation};
pub use chess_piece::piece;
pub use chess_piece::pieces::{bishop, king, knight, pawn, queen, rook};

#[cfg(test)]
mod test {
    use crate::{chess_board::board::Board, coordinates::Coordinates, notation::Notation};

    #[test]
    // Creating a Notation and Coordinates object.
    fn create_notation_and_coordinates() {
        // Creates a Notation from chars. ('file' 'rank').
        let notation: Notation = Notation::new('e', '4').unwrap();

        // Creates Coordinates from an i8. (x, y).
        let coordinates: Coordinates = Coordinates::new(5, 4);

        // Checks if the converted notation is equal to coordinates.
        assert_eq!(coordinates, notation.to_coordinates().unwrap());
        // Checks if the converted coordinates is equal to notation.
        assert_eq!(notation, coordinates.to_notation().unwrap());

        // Creates a Notation from string. ("e4").
        let notation_from_string: Notation = Notation::from_string("e4").unwrap();

        // Creates Coordinates from a string of 2 i8 separated by a comma.
        // ("4.3").
        let coordinate_from_string: Coordinates = Coordinates::from_string("5,4").unwrap();

        // Checks if the converted notation is equal to coordinates.
        assert_eq!(
            coordinate_from_string,
            notation_from_string.to_coordinates().unwrap()
        );

        // Checks if the converted coordinates is equal to notation.
        assert_eq!(
            notation_from_string,
            coordinate_from_string.to_notation().unwrap()
        );
    }

    // Creating a board object
    #[test]
    fn create_chess_board() {
        // Creates a 2D board, With starting pieces.
        let two_dimensional_board = Board::new_two_dimensional_starting_position();

        // Creates a 1D board, With starting pieces.
        let one_dimensional_board = Board::new_one_dimensional_starting_position();

        // For checking the boards.
        dbg!(one_dimensional_board);
        dbg!(two_dimensional_board);
    }
}