test: implement date parsing and sorting unit tests using real-world CSV activity data. Improved OSs sort
This commit is contained in:
@@ -88,6 +88,82 @@ class ExampleUnitTest {
|
||||
assertEquals(15, cal2.get(Calendar.MINUTE))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParseFullDateTimeWithCsvFormats() {
|
||||
// Tests real date formats from documentacao/exemplo_testes/GestaoOS_Parada_project.csv
|
||||
val csvDates = listOf(
|
||||
"ter. 04/08/26 07:00",
|
||||
"sex. 14/08/26 07:00",
|
||||
"seg. 17/08/26 07:00",
|
||||
"ter. 18/08/26 17:00",
|
||||
"qua. 19/08/26 07:00",
|
||||
"qui. 27/08/26 17:00",
|
||||
"sáb. 22/08/26 07:00",
|
||||
"qua. 02/09/26 17:00",
|
||||
"sex. 11/09/26 16:00"
|
||||
)
|
||||
|
||||
for (str in csvDates) {
|
||||
val parsed = parseFullDateTime(str)
|
||||
assertNotNull("Failed to parse CSV date format: $str", parsed)
|
||||
}
|
||||
|
||||
val d1 = parseFullDateTime("sex. 14/08/26 07:00")!!
|
||||
val d2 = parseFullDateTime("ter. 18/08/26 17:00")!!
|
||||
val d3 = parseFullDateTime("qua. 02/09/26 17:00")!!
|
||||
assertTrue(d1.before(d2))
|
||||
assertTrue(d2.before(d3))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSortingChronologicalOrderWithCsvData() {
|
||||
// Activities created using real entries from documentacao/exemplo_testes/GestaoOS_Parada_project.csv
|
||||
val act1 = com.example.data.model.MaintenanceActivity(
|
||||
numeroOs = "1", descricao = "PARADA ANUAL 2026", setor = "Geral", equipe = "Mecânica", recurso = "Sem Recurso",
|
||||
dataInicio = "ter. 04/08/26 07:00", dataFim = "sex. 11/09/26 16:00", percentualExecucao = 0
|
||||
)
|
||||
val act3 = com.example.data.model.MaintenanceActivity(
|
||||
numeroOs = "3", descricao = "UTILIDADES", setor = "Geral", equipe = "Mecânica", recurso = "Sem Recurso",
|
||||
dataInicio = "sex. 14/08/26 07:00", dataFim = "qua. 02/09/26 17:00", percentualExecucao = 0
|
||||
)
|
||||
val act4 = com.example.data.model.MaintenanceActivity(
|
||||
numeroOs = "4", descricao = "B-111113", setor = "Geral", equipe = "Mecânica", recurso = "Sem Recurso",
|
||||
dataInicio = "sex. 14/08/26 07:00", dataFim = "sex. 14/08/26 07:00", percentualExecucao = 0
|
||||
)
|
||||
val act1024 = com.example.data.model.MaintenanceActivity(
|
||||
numeroOs = "1024", descricao = "SUBSTITUIÇÃO DA CHAPA DE FIXAÇÃO DOS APARADORES", setor = "Geral", equipe = "Mecânica", recurso = "GTEC 1",
|
||||
dataInicio = "seg. 17/08/26 07:00", dataFim = "ter. 18/08/26 17:00", percentualExecucao = 0
|
||||
)
|
||||
val act1025 = com.example.data.model.MaintenanceActivity(
|
||||
numeroOs = "1025", descricao = "FABRICAÇÃO E MONTAGEM DA BASE ACIONAMENTO", setor = "Geral", equipe = "Mecânica", recurso = "GTEC 3",
|
||||
dataInicio = "seg. 17/08/26 07:00", dataFim = "qua. 19/08/26 17:00", percentualExecucao = 0
|
||||
)
|
||||
val act875 = com.example.data.model.MaintenanceActivity(
|
||||
numeroOs = "875", descricao = "SUBSTITUIR APARADORES DA CORREIA", setor = "Geral", equipe = "Mecânica", recurso = "LEANDRO",
|
||||
dataInicio = "qua. 26/08/26 07:00", dataFim = "qui. 27/08/26 17:00", percentualExecucao = 0
|
||||
)
|
||||
|
||||
val unorganizedList = listOf(act1, act3, act1025, act1024, act875, act4)
|
||||
|
||||
val sortedList = unorganizedList.sortedWith { a1, a2 ->
|
||||
val p1 = parseFullDateTime(a1.dataFim)
|
||||
val p2 = parseFullDateTime(a2.dataFim)
|
||||
when {
|
||||
p1 == null && p2 == null -> a1.numeroOs.compareTo(a2.numeroOs)
|
||||
p1 == null -> 1
|
||||
p2 == null -> -1
|
||||
else -> {
|
||||
val comp = p1.compareTo(p2)
|
||||
if (comp != 0) comp else a1.numeroOs.compareTo(a2.numeroOs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val sortedOsNumbers = sortedList.map { it.numeroOs }
|
||||
val expectedOsNumbers = listOf("4", "1024", "1025", "875", "3", "1")
|
||||
assertEquals(expectedOsNumbers, sortedOsNumbers)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFormatToShortDate() {
|
||||
assertEquals("14/08/26", formatToShortDate("Sex 14/08/26 07:00"))
|
||||
|
||||
Reference in New Issue
Block a user