change the parser to manage accent, add splitlanguages tests (to test if html css and js are seperated) and test if the parsing works great
parent
50a381a1c3
commit
e47b726467
|
@ -49,7 +49,7 @@ fun splitLanguages(file : String){
|
|||
|
||||
fun parser(fileName : String) {
|
||||
val delimiter1 = " "
|
||||
val regex = "[^a-zA-Z]".toRegex()
|
||||
val regex = "[^a-zA-Z^é^à]".toRegex()
|
||||
val array = mutableListOf<String>()
|
||||
|
||||
val line = delStrings(takeOnlyJs(fileName)).toString().replace(regex, " ").toString()
|
||||
|
|
|
@ -3,13 +3,15 @@ package main
|
|||
import junit.framework.TestCase.assertEquals
|
||||
import junit.framework.TestCase.assertTrue
|
||||
import org.junit.Test
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
|
||||
class ParserTest {
|
||||
|
||||
@Test
|
||||
fun testDelStrings() {
|
||||
val input = "This is a \"sample\" string."
|
||||
val input = "This is a \"sample\"string."
|
||||
val output = delStrings(input)
|
||||
assertEquals("This is a string.", output)
|
||||
}
|
||||
|
@ -55,4 +57,37 @@ class ParserTest {
|
|||
assertTrue(actualHtmlCode.contains("<link href=\"css.css\" rel=\"stylesheet\" />"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParser() {
|
||||
// Assume you have a sample HTML file for testing
|
||||
val puissance4File = "src/test/resources/puissance4.html"
|
||||
|
||||
// Call the parser function
|
||||
parser(puissance4File)
|
||||
|
||||
// Verify the output by capturing the printed content
|
||||
val printedContent = captureStandardOutput {
|
||||
parser(puissance4File)
|
||||
}
|
||||
|
||||
// Assert the expected output based on the content of your sample HTML file
|
||||
val expectedOutput =File("src/test/resources/ExpectedParsingResult.txt").readText().trimIndent()
|
||||
|
||||
assertEquals(expectedOutput, printedContent.trimIndent())
|
||||
}
|
||||
|
||||
// Function to capture standard output
|
||||
private fun captureStandardOutput(block: () -> Unit): String {
|
||||
val standardOut = System.out
|
||||
val outputStream = ByteArrayOutputStream()
|
||||
System.setOut(PrintStream(outputStream))
|
||||
|
||||
try {
|
||||
block()
|
||||
} finally {
|
||||
System.setOut(standardOut)
|
||||
}
|
||||
|
||||
return outputStream.toString().trim()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
plateau : 2
|
||||
creercell : 2
|
||||
numcolonnes : 3
|
||||
coupsJoues : 3
|
||||
numrangées : 4
|
||||
joueurActuel : 5
|
||||
cells : 9
|
||||
colonne : 16
|
||||
rangée : 18
|
||||
cell : 21
|
|
@ -0,0 +1,150 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
.plateau {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 7%); /* Chaque colonne occupe la même fraction de l'espace disponible */
|
||||
}
|
||||
.cell {
|
||||
width: 100%;
|
||||
padding-top: 100%; /* Pour garder les cases carrées */
|
||||
border: 1px solid #000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
border-radius: 50%; /* Pour créer des cercles */
|
||||
}
|
||||
.rouge {
|
||||
background-color: red;
|
||||
border-radius: 50%; /* Pour créer des cercles */
|
||||
}
|
||||
.jaune {
|
||||
background-color: yellow;
|
||||
border-radius: 50%; /* Pour créer des cercles */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="plateau" id="plateau"></div>
|
||||
<script>
|
||||
const numrangées = 6;
|
||||
const numcolonnes = 7;
|
||||
const plateau = document.getElementById("plateau");
|
||||
let coupsJoues = 0;
|
||||
let joueurActuel = "rouge";
|
||||
const cells = [];
|
||||
|
||||
function creercell(rangée, colonne) {
|
||||
const cell = document.createElement("div");
|
||||
cell.classList.add("cell");
|
||||
cell.dataset.row = rangée;
|
||||
cell.dataset.col = colonne;
|
||||
plateau.appendChild(cell);
|
||||
cells.push(cell);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function changeJoueur() {
|
||||
joueurActuel = joueurActuel === "rouge" ? "jaune" : "rouge";
|
||||
}
|
||||
|
||||
function verifVictoire(rangée, colonne) {
|
||||
const currentcell = cells.find(c => parseInt(c.dataset.row) === rangée && parseInt(c.dataset.col) === colonne);
|
||||
const currentColor = currentcell.classList.contains("rouge") ? "rouge" : "jaune";
|
||||
|
||||
// verif alignement horizontal
|
||||
let count = 0;
|
||||
for (let i = colonne - 3; i <= colonne + 3; i++) {
|
||||
const cell = cells.find(c => parseInt(c.dataset.row) === rangée && parseInt(c.dataset.col) === i);
|
||||
if (cell && cell.classList.contains(currentColor)) {
|
||||
count++;
|
||||
if (count === 4) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// verif alignement vertical
|
||||
count = 0;
|
||||
for (let i = rangée - 3; i <= rangée + 3; i++) {
|
||||
const cell = cells.find(c => parseInt(c.dataset.row) === i && parseInt(c.dataset.col) === colonne);
|
||||
if (cell && cell.classList.contains(currentColor)) {
|
||||
count++;
|
||||
if (count === 4) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// verif alignement diagonal
|
||||
count = 0;
|
||||
for (let i = -3; i <= 3; i++) {
|
||||
const cell = cells.find(c => parseInt(c.dataset.row) === rangée + i && parseInt(c.dataset.col) === colonne + i);
|
||||
if (cell && cell.classList.contains(currentColor)) {
|
||||
count++;
|
||||
if (count === 4) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// verif alignement anti-diagonal
|
||||
count = 0;
|
||||
for (let i = -3; i <= 3; i++) {
|
||||
const cell = cells.find(c => parseInt(c.dataset.row) === rangée - i && parseInt(c.dataset.col) === colonne + i);
|
||||
if (cell && cell.classList.contains(currentColor)) {
|
||||
count++;
|
||||
if (count === 4) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let rangée = 0; rangée < numrangées; rangée++) {
|
||||
for (let colonne = 0; colonne < numcolonnes; colonne++) {
|
||||
creercell(rangée, colonne);
|
||||
}
|
||||
}
|
||||
|
||||
cells.forEach(cell => {
|
||||
cell.addEventListener("click", function () {
|
||||
const colonne = parseInt(cell.dataset.col);
|
||||
|
||||
for (let rangée = numrangées - 1; rangée >= 0; rangée--) {
|
||||
const currentcell = cells.find(c => parseInt(c.dataset.row) === rangée && parseInt(c.dataset.col) === colonne);
|
||||
if (!currentcell.classList.contains("rouge") && !currentcell.classList.contains("jaune")) {
|
||||
currentcell.classList.add(joueurActuel);
|
||||
coupsJoues++;
|
||||
if (verifVictoire(rangée, colonne)) {
|
||||
alert("Joueur " + joueurActuel + " a gagné !");
|
||||
location.reload();
|
||||
}else if (coupsJoues === numrangées * numcolonnes) {
|
||||
alert("Égalité ! Aucun joueur n'a gagné.");
|
||||
location.reload();
|
||||
}
|
||||
else {
|
||||
changeJoueur();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue