package floor

import "testing"

func Test_Read_Exemple(t *testing.T) {
	var matriceOut [][]int = [][]int{
		{1, 1, 3, 4},
		{1, 1, 4, 3},
		{0, 0, 2, 2},
		{0, 0, 2, 2},
	}
	if !Equal(readFloorFromFile("../floor-files/exemple"), matriceOut) {
		t.Error("erreur")
	}
}

func Test_Read_validation(t *testing.T) {
	var matriceOut [][]int = [][]int{
		{0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0},
		{1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 1, 2, 1, 2, 2, 2, 1},
		{0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0},
		{1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1},
		{0, 2, 0, 2, 0, 2, 2, 1, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0},
		{1, 2, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0, 2, 0, 1, 2, 2, 2, 1},
		{0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0},
	}
	if !Equal(readFloorFromFile("../floor-files/validation"), matriceOut) {
		t.Error(readFloorFromFile("../floor-files/validation"))
	}
}

func Test_Read_beaupasbeau(t *testing.T) {
	var matriceOut [][]int = [][]int{
		{0, 0, 1, 0, 2, 2, 2, 2},
		{0, 0, 1, 0, 2, 2, 2, 2},
		{0, 0, 1, 0, 2, 2, 2, 2},
		{0, 0, 1, 1, 0, 0, 0, 0},
		{0, 0, 0, 1, 1, 1, 0, 0},
		{2, 2, 0, 0, 0, 1, 0, 0},
		{2, 2, 2, 0, 0, 1, 0, 0},
		{2, 2, 2, 0, 0, 1, 0, 0},
	}
	if !Equal(readFloorFromFile("../floor-files/beaupasbeau"), matriceOut) {
		t.Error(readFloorFromFile("../floor-files/beaupasbeau"))
	}
}

// Test Terrain 1x1
func Test_Read_1x1(t *testing.T) {
	var matriceOut [][]int = [][]int{{0}}
	if !Equal(readFloorFromFile("../floor-files/1x1.txt"), matriceOut) {
		t.Error(readFloorFromFile("../floor-files/1x1.txt"))
	}
}

// Test Terrain Vide
func Test_Read_vide(t *testing.T) {
	var matriceOut [][]int = [][]int{}
	//h := readFloorFromFile("../floor-files/vide.txt")
	//fmt.Println(h, matriceOut)
	if !Equal(readFloorFromFile("../floor-files/vide.txt"), matriceOut) {
		t.Error(readFloorFromFile("../floor-files/vide.txt"))
	}
}

// Fonction pour tester l'égalité entre les deux listes de listes

func Equal(Liste1 [][]int, Liste2 [][]int) (egale bool) {

	if len(Liste1) != len(Liste2) {
		return false
	} else {
		for i := 0; i < len(Liste1); i++ {
			if len(Liste1[i]) != len(Liste2[i]) {
				return false
			} else {
				for j := 0; j < len(Liste1[i]); j++ {
					if Liste1[i][j] != Liste2[i][j] {
						return false
					}
				}
			}
		}
		return true
	}
}
