Added legend + some tests

main
Cemal Odabasioglu 2023-12-21 15:14:59 +01:00
parent 1938a0282f
commit 8d46370f42
4 changed files with 66 additions and 8 deletions

View File

@ -39,9 +39,12 @@ dependencies {
testImplementation("junit:junit:4.13.1") testImplementation("junit:junit:4.13.1")
implementation("org.apache.poi:poi:5.0.0") implementation("org.apache.poi:poi:5.0.0")
implementation("org.apache.poi:poi-ooxml:5.0.0") implementation("org.apache.poi:poi-ooxml:5.0.0")
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
} }
compose.desktop { compose.desktop {
application { application {
mainClass = "MainKt" mainClass = "MainKt"

View File

@ -6,7 +6,6 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.Button import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -29,15 +28,24 @@ fun compareResults(
verticalArrangement = Arrangement.Top, verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
Text(
text = "Le code contient ${commonWords.size}% des mots du glossaire",
style = MaterialTheme.typography.h3
)
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
commonWordsTable(glossaryWords, codeWords) commonWordsTable(glossaryWords, codeWords)
Spacer(modifier = Modifier.height(16.dp))
// Légende
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
LegendItem(color = Color.Green, label = "Mot dans le glossaire et dans le code")
LegendItem(color = Color.White, label = "Mot seulement dans le glossaire")
LegendItem(color = Color.Yellow, label = "Mot seulement dans le code")
}
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
Button( Button(
@ -52,6 +60,7 @@ fun compareResults(
} }
} }
// Ajouter une légende au tableau
@OptIn(ExperimentalFoundationApi::class) @OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
fun commonWordsTable( fun commonWordsTable(
@ -62,7 +71,6 @@ fun commonWordsTable(
Box( Box(
modifier = Modifier modifier = Modifier
// Les 3/4 de l'écran
.height(500.dp) .height(500.dp)
.padding(10.dp) .padding(10.dp)
) { ) {
@ -91,6 +99,24 @@ fun commonWordsTable(
} }
} }
@Composable
fun LegendItem(color: Color, label: String) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
Box(
modifier = Modifier
.width(24.dp)
.height(14.dp)
.background(color)
.border(1.dp, Color.Black)
)
Text(text = label)
}
}
@Composable @Composable
fun commonWordsHeaderRow() { fun commonWordsHeaderRow() {
Row( Row(

View File

@ -15,7 +15,6 @@ import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusOrder
import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.* import androidx.compose.ui.input.key.*
@ -225,7 +224,7 @@ fun formPage(glossary: Glossary, onCancelClick: () -> Unit) {
TextField( TextField(
value = secondaryContext.value, value = secondaryContext.value,
onValueChange = { secondaryContext.value = it }, onValueChange = { secondaryContext.value = it },
label = { Text("Contexte 2") }, label = { Text("Contexte secondaire") },
singleLine = true, singleLine = true,
colors = TextFieldDefaults.textFieldColors( colors = TextFieldDefaults.textFieldColors(
focusedIndicatorColor = customRedColor, focusedIndicatorColor = customRedColor,

View File

@ -0,0 +1,30 @@
package main
import org.junit.Test
import org.junit.jupiter.api.Assertions.*
class MainKtTest {
@Test
fun valid_file_names() {
val validFileNames = listOf("example", "file123", "my-file_01")
for (fileName in validFileNames) {
val isValid = isValidFileName(fileName)
assertEquals(true, isValid, "Expected $fileName to be a valid file name")
}
}
@Test
fun invalid_file_names() {
val invalidFileNames = listOf("file name", "file*123", "my/file")
for (fileName in invalidFileNames) {
val isValid = isValidFileName(fileName)
assertEquals(false, isValid, "Expected $fileName to be an invalid file name")
}
}
}