feat(web): java from python
Some checks failed
Build, Test and Deploy / build-and-push (push) Has been cancelled
Build, Test and Deploy / deploy (push) Has been cancelled
Build, Test and Deploy / test-backend (push) Has been cancelled

This commit is contained in:
2026-02-02 19:40:58 +01:00
parent 316c74e299
commit ceeb831a41
41 changed files with 891 additions and 5008 deletions

View File

@@ -0,0 +1,57 @@
package com.printcalculator.service;
import com.printcalculator.model.PrintStats;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.*;
class GCodeParserTest {
@Test
void parse_validGcode_returnsCorrectStats() throws IOException {
// Arrange
File tempFile = File.createTempFile("test", ".gcode");
try (FileWriter writer = new FileWriter(tempFile)) {
writer.write("; generated by OrcaSlicer\n");
writer.write("; estimated printing time = 1h 2m 3s\n");
writer.write("; filament used [g] = 10.5\n");
writer.write("; filament used [mm] = 3000.0\n");
}
GCodeParser parser = new GCodeParser();
// Act
PrintStats stats = parser.parse(tempFile);
// Assert
assertEquals(3723, stats.printTimeSeconds()); // 3600 + 120 + 3
assertEquals("1h 2m 3s", stats.printTimeFormatted());
assertEquals(10.5, stats.filamentWeightGrams(), 0.001);
assertEquals(3000.0, stats.filamentLengthMm(), 0.001);
tempFile.delete();
}
@Test
void parse_footerGcode_returnsCorrectStats() throws IOException {
// Arrange
File tempFile = File.createTempFile("test_footer", ".gcode");
try (FileWriter writer = new FileWriter(tempFile)) {
writer.write("; header\n");
// ... many lines ...
writer.write("; filament used [g] = 5.0\n");
writer.write("; estimated printing time = 12m 30s\n");
}
GCodeParser parser = new GCodeParser();
PrintStats stats = parser.parse(tempFile);
assertEquals(750, stats.printTimeSeconds()); // 12*60 + 30
assertEquals(5.0, stats.filamentWeightGrams(), 0.001);
tempFile.delete();
}
}