<commit_before>package sudoku_test

import (
	"fmt"
	"testing"

	"github.com/laurentlp/sudoku-solver/sudoku"
)

const digits string = "123456789"
const rows string = "ABCDEFGHI"
const cols string = digits
const grid = "4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......"
const gridEasy = "003020600900305001001806400008102900700000008006708200002609500800203009005010300"
const gridHard = ".....6....59.....82....8....45........3........6..3.54...325..6.................."
const errorGrid = "4.....8.5.3..........7......2.....6.....8.4......1...."

var squares []string
var unitList [][]string
var squareUnits map[string][][]string
var squarePeers map[string]map[string]bool

func TestCross(t *testing.T) {
	squares = sudoku.Cross(rows, cols)

	if len(squares) != 81 {
		t.Error("Expected 81 squares")
	}
}

func TestUnitList(t *testing.T) {
	unitList = sudoku.CreateUnitList(rows, cols)

	var tot int
	for _, u := range unitList {
		tot += len(u)
	}

	if tot != 81*3 {
		t.Error("Expected 243 squares got : ", tot)
	}
}

func TestCreateUnits(t *testing.T) {
	squareUnits = sudoku.CreateUnits(squares, unitList)
	for _, u := range squareUnits {
		if len(u) != 3 {
			t.Error("Unit length expected 3 got : ", len(u))
		}
	}
}

func TestUnit(t *testing.T) {
	unit := [][]string{
		[]string{"A2", "B2", "C2", "D2", "E2", "F2", "G2", "H2", "I2"},
		[]string{"C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9"},
		[]string{"A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"},
	}

	c2 := squareUnits["C2"]
	if !compareSlices3D(c2, unit) {
		t.Error("An error occured while creating units. Some returned values are wrong !")
	}
}

func TestCreatePeers(t *testing.T) {
	squarePeers = sudoku.CreatePeers(squareUnits)
	for k, p := range squarePeers {
		if len(p) != 20 {
			t.Error("Peers length expected 20 got : ", len(squarePeers[k]), " for the square ", k)
		}
	}
}

func TestPeers(t *testing.T) {
	unit := []string{
		"A2", "B2", "D2", "E2", "F2", "G2", "H2", "I2",
		"C1", "C3", "C4", "C5", "C6", "C7", "C8", "C9",
		"A1", "A3", "B1", "B3",
	}

	c2 := squarePeers["C2"]
	if compareSlices2D(c2, unit) {
		t.Error("An error occured while creating peers. Some returned values are wrong !")
	}
}

func TestGrid(t *testing.T) {
	result := map[string]string{}

	for i, s := range squares {
		result[s] = string(grid[i])
	}

	values, err := sudoku.GridValues(grid)

	if len(values) != len(grid) {
		t.Error(err)
	}

	for k, v := range values {<commit_msg>Fix type<commit_after>package sudoku_test

import (
	"fmt"
	"testing"

	"github.com/laurentlp/sudoku-solver/sudoku"
)

const digits string = "123456789"
const rows string = "ABCDEFGHI"
const cols string = digits
const grid = "4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......"
const gridEasy = "003020600900305001001806400008102900700000008006708200002609500800203009005010300"
const gridHard = ".....6....59.....82....8....45........3........6..3.54...325..6.................."
const errorGrid = "4.....8.5.3..........7......2.....6.....8.4......1...."

var squares []string
var unitList [][]string
var squareUnits map[string][][]string
var squarePeers map[string]map[string]bool

func TestCross(t *testing.T) {
	squares = sudoku.Cross(rows, cols)

	if len(squares) != 81 {
		t.Error("Expected 81 squares")
	}
}

func TestUnitList(t *testing.T) {
	unitList = sudoku.CreateUnitList(rows, cols)

	var tot int
	for _, u := range unitList {
		tot += len(u)
	}

	if tot != 81*3 {
		t.Error("Expected 243 squares got : ", tot)
	}
}

func TestCreateUnits(t *testing.T) {
	squareUnits = sudoku.CreateUnits(squares, unitList)
	for _, u := range squareUnits {
		if len(u) != 3 {
			t.Error("Unit length expected 3 got : ", len(u))
		}
	}
}

func TestUnit(t *testing.T) {
	unit := [][]string{
		[]string{"A2", "B2", "C2", "D2", "E2", "F2", "G2", "H2", "I2"},
		[]string{"C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9"},
		[]string{"A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"},
	}

	c2 := squareUnits["C2"]
	if !compareSlices3D(c2, unit) {
		t.Error("An error occurred while creating units. Some returned values are wrong !")
	}
}

func TestCreatePeers(t *testing.T) {
	squarePeers = sudoku.CreatePeers(squareUnits)
	for k, p := range squarePeers {
		if len(p) != 20 {
			t.Error("Peers length expected 20 got : ", len(squarePeers[k]), " for the square ", k)
		}
	}
}

func TestPeers(t *testing.T) {
	unit := []string{
		"A2", "B2", "D2", "E2", "F2", "G2", "H2", "I2",
		"C1", "C3", "C4", "C5", "C6", "C7", "C8", "C9",
		"A1", "A3", "B1", "B3",
	}

	c2 := squarePeers["C2"]
	if compareSlices2D(c2, unit) {
		t.Error("An error occurred while creating peers. Some returned values are wrong !")
	}
}

func TestGrid(t *testing.T) {
	result := map[string]string{}

	for i, s := range squares {
		result[s] = string(grid[i])
	}

	values, err := sudoku.GridValues(grid)

	if len(values) != len(grid) {
		t.Error(err)
	}

	for k, v := range values {
{'fraction_non_alphanumeric': 0.2437941473259334, 'fraction_numerical': 0.08274470232088799, 'mean_word_length': 3.089108910891089, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6680286', 'n_tokens_mistral': 2282, 'n_tokens_neox': 2051, 'n_words': 465}