Skip to content

Commit be2b3b4

Browse files
committed
test message
1 parent 53e47bc commit be2b3b4

9 files changed

+185
-185
lines changed

src/test/java/prog/MainFrameTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ void testFileOpenOperation() throws InterruptedException, IOException {
105105
assertTrue(latch.await(5, TimeUnit.SECONDS), "Frame initialization timed out");
106106

107107
// Simulate file selection
108-
Main.opened_file = testFile;
109-
Main.past = testFile.length();
110-
Main.redScore.setText(Main.past + "Bytes");
111-
Main.blueScore.setText("NotYetCalculated");
112-
113-
assertEquals(testFile, Main.opened_file, "Selected file should be set");
114-
assertEquals(testFile.length(), Main.past, "File size should be set");
115-
assertEquals(testFile.length() + "Bytes", Main.redScore.getText(), "Red score should show file size");
116-
assertEquals("NotYetCalculated", Main.blueScore.getText(), "Blue score should show not calculated");
108+
Main.openedFile = testFile;
109+
Main.originalSize = testFile.length();
110+
Main.originalSizeValue.setText(Main.originalSize + "Bytes");
111+
Main.compressedSizeValue.setText("NotYetCalculated");
112+
113+
assertEquals(testFile, Main.openedFile, "Selected file should be set");
114+
assertEquals(testFile.length(), Main.originalSize, "File size should be set");
115+
assertEquals(testFile.length() + "Bytes", Main.originalSizeValue.getText(), "Original size should show file size");
116+
assertEquals("NotYetCalculated", Main.compressedSizeValue.getText(), "Compressed size should show not calculated");
117117

118118
SwingUtilities.invokeLater(() -> mainFrame.dispose());
119119
}

src/test/java/prog/MainPanelTest.java

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,29 @@ void testTitlePanelProperties() {
4040
assertNotNull(Main.titlePanel, "Title panel should be created");
4141
assertEquals(new Point(90, 20), Main.titlePanel.getLocation(), "Title panel location should match");
4242
assertEquals(new Dimension(170, 70), Main.titlePanel.getSize(), "Title panel size should match");
43-
43+
4444
// Test labels in title panel
45-
assertEquals("Selected File Size: ", Main.redLabel.getText(), "Red label text should match");
46-
assertEquals("After zip/unzip the file size: ", Main.blueLabel.getText(), "Blue label text should match");
47-
45+
assertEquals("Selected File Size: ", Main.originalSizeLabel.getText(), "Original size label text should match");
46+
assertEquals("After zip/unzip the file size: ", Main.compressedSizeLabel.getText(), "Compressed size label text should match");
47+
4848
// Test label alignment
49-
assertEquals(SwingConstants.CENTER, Main.redLabel.getHorizontalAlignment(), "Red label should be center-aligned");
50-
assertEquals(SwingConstants.CENTER, Main.blueLabel.getHorizontalAlignment(), "Blue label should be center-aligned");
49+
assertEquals(SwingConstants.CENTER, Main.originalSizeLabel.getHorizontalAlignment(), "Original size label should be center-aligned");
50+
assertEquals(SwingConstants.CENTER, Main.compressedSizeLabel.getHorizontalAlignment(), "Compressed size label should be center-aligned");
5151
}
5252

5353
@Test
5454
void testScorePanelProperties() {
5555
assertNotNull(Main.scorePanel, "Score panel should be created");
5656
assertEquals(new Point(270, 20), Main.scorePanel.getLocation(), "Score panel location should match");
5757
assertEquals(new Dimension(120, 60), Main.scorePanel.getSize(), "Score panel size should match");
58-
58+
5959
// Test score labels
60-
assertEquals("", Main.redScore.getText(), "Red score should be empty initially");
61-
assertEquals("", Main.blueScore.getText(), "Blue score should be empty initially");
62-
60+
assertEquals("", Main.originalSizeValue.getText(), "Original size value should be empty initially");
61+
assertEquals("", Main.compressedSizeValue.getText(), "Compressed size value should be empty initially");
62+
6363
// Test label alignment
64-
assertEquals(SwingConstants.CENTER, Main.redScore.getHorizontalAlignment(), "Red score should be center-aligned");
65-
assertEquals(SwingConstants.CENTER, Main.blueScore.getHorizontalAlignment(), "Blue score should be center-aligned");
64+
assertEquals(SwingConstants.CENTER, Main.originalSizeValue.getHorizontalAlignment(), "Original size value should be center-aligned");
65+
assertEquals(SwingConstants.CENTER, Main.compressedSizeValue.getHorizontalAlignment(), "Compressed size value should be center-aligned");
6666
}
6767

6868
@Test
@@ -76,52 +76,52 @@ void testButtonPanelProperties() {
7676
@Test
7777
void testButtonProperties() {
7878
// Test ZIP HuffZ button
79-
assertEquals("ZIP HuffZ", Main.ZH.getText(), "ZIP HuffZ button text should match");
80-
assertEquals(new Point(0, 0), Main.ZH.getLocation(), "ZIP HuffZ button location should match");
81-
assertEquals(new Dimension(120, 30), Main.ZH.getSize(), "ZIP HuffZ button size should match");
79+
assertEquals("ZIP HuffZ", Main.huffmanCompressButton.getText(), "ZIP HuffZ button text should match");
80+
assertEquals(new Point(0, 0), Main.huffmanCompressButton.getLocation(), "ZIP HuffZ button location should match");
81+
assertEquals(new Dimension(120, 30), Main.huffmanCompressButton.getSize(), "ZIP HuffZ button size should match");
8282

8383
// Test UNZIP HuffZ button
84-
assertEquals("UNZIP HuffZ", Main.UH.getText(), "UNZIP HuffZ button text should match");
85-
assertEquals(new Point(130, 0), Main.UH.getLocation(), "UNZIP HuffZ button location should match");
86-
assertEquals(new Dimension(120, 30), Main.UH.getSize(), "UNZIP HuffZ button size should match");
84+
assertEquals("UNZIP HuffZ", Main.huffmanDecompressButton.getText(), "UNZIP HuffZ button text should match");
85+
assertEquals(new Point(130, 0), Main.huffmanDecompressButton.getLocation(), "UNZIP HuffZ button location should match");
86+
assertEquals(new Dimension(120, 30), Main.huffmanDecompressButton.getSize(), "UNZIP HuffZ button size should match");
8787

8888
// Test ZIP LmZWp button
89-
assertEquals("ZIP LmZWp", Main.ZL.getText(), "ZIP LmZWp button text should match");
90-
assertEquals(new Point(260, 0), Main.ZL.getLocation(), "ZIP LmZWp button location should match");
91-
assertEquals(new Dimension(120, 30), Main.ZL.getSize(), "ZIP LmZWp button size should match");
89+
assertEquals("ZIP LmZWp", Main.lzwCompressButton.getText(), "ZIP LmZWp button text should match");
90+
assertEquals(new Point(260, 0), Main.lzwCompressButton.getLocation(), "ZIP LmZWp button location should match");
91+
assertEquals(new Dimension(120, 30), Main.lzwCompressButton.getSize(), "ZIP LmZWp button size should match");
9292

9393
// Test UNZIP LmZWp button
94-
assertEquals("UNZIP LmZWp", Main.UL.getText(), "UNZIP LmZWp button text should match");
95-
assertEquals(new Point(390, 0), Main.UL.getLocation(), "UNZIP LmZWp button location should match");
96-
assertEquals(new Dimension(120, 30), Main.UL.getSize(), "UNZIP LmZWp button size should match");
94+
assertEquals("UNZIP LmZWp", Main.lzwDecompressButton.getText(), "UNZIP LmZWp button text should match");
95+
assertEquals(new Point(390, 0), Main.lzwDecompressButton.getLocation(), "UNZIP LmZWp button location should match");
96+
assertEquals(new Dimension(120, 30), Main.lzwDecompressButton.getSize(), "UNZIP LmZWp button size should match");
9797

9898
// Test EXIT button
99-
assertEquals("EXIT", Main.EX.getText(), "EXIT button text should match");
100-
assertEquals(new Point(130, 70), Main.EX.getLocation(), "EXIT button location should match");
101-
assertEquals(new Dimension(250, 30), Main.EX.getSize(), "EXIT button size should match");
99+
assertEquals("EXIT", Main.exitButton.getText(), "EXIT button text should match");
100+
assertEquals(new Point(130, 70), Main.exitButton.getLocation(), "EXIT button location should match");
101+
assertEquals(new Dimension(250, 30), Main.exitButton.getSize(), "EXIT button size should match");
102102
}
103103

104104
@Test
105105
void testButtonActionListeners() {
106106
// Verify that all buttons have action listeners attached
107-
assertNotNull(Main.ZH.getActionListeners(), "ZIP HuffZ button should have action listener");
108-
assertNotNull(Main.UH.getActionListeners(), "UNZIP HuffZ button should have action listener");
109-
assertNotNull(Main.ZL.getActionListeners(), "ZIP LmZWp button should have action listener");
110-
assertNotNull(Main.UL.getActionListeners(), "UNZIP LmZWp button should have action listener");
111-
assertNotNull(Main.EX.getActionListeners(), "EXIT button should have action listener");
112-
113-
assertEquals(1, Main.ZH.getActionListeners().length, "ZIP HuffZ button should have exactly one listener");
114-
assertEquals(1, Main.UH.getActionListeners().length, "UNZIP HuffZ button should have exactly one listener");
115-
assertEquals(1, Main.ZL.getActionListeners().length, "ZIP LmZWp button should have exactly one listener");
116-
assertEquals(1, Main.UL.getActionListeners().length, "UNZIP LmZWp button should have exactly one listener");
117-
assertEquals(1, Main.EX.getActionListeners().length, "EXIT button should have exactly one listener");
118-
107+
assertNotNull(Main.huffmanCompressButton.getActionListeners(), "ZIP HuffZ button should have action listener");
108+
assertNotNull(Main.huffmanDecompressButton.getActionListeners(), "UNZIP HuffZ button should have action listener");
109+
assertNotNull(Main.lzwCompressButton.getActionListeners(), "ZIP LmZWp button should have action listener");
110+
assertNotNull(Main.lzwDecompressButton.getActionListeners(), "UNZIP LmZWp button should have action listener");
111+
assertNotNull(Main.exitButton.getActionListeners(), "EXIT button should have action listener");
112+
113+
assertEquals(1, Main.huffmanCompressButton.getActionListeners().length, "ZIP HuffZ button should have exactly one listener");
114+
assertEquals(1, Main.huffmanDecompressButton.getActionListeners().length, "UNZIP HuffZ button should have exactly one listener");
115+
assertEquals(1, Main.lzwCompressButton.getActionListeners().length, "ZIP LmZWp button should have exactly one listener");
116+
assertEquals(1, Main.lzwDecompressButton.getActionListeners().length, "UNZIP LmZWp button should have exactly one listener");
117+
assertEquals(1, Main.exitButton.getActionListeners().length, "EXIT button should have exactly one listener");
118+
119119
// Verify that all buttons have the same listener instance
120-
ActionListener zhListener = Main.ZH.getActionListeners()[0];
121-
assertSame(zhListener, Main.UH.getActionListeners()[0], "All buttons should share the same listener");
122-
assertSame(zhListener, Main.ZL.getActionListeners()[0], "All buttons should share the same listener");
123-
assertSame(zhListener, Main.UL.getActionListeners()[0], "All buttons should share the same listener");
124-
assertSame(zhListener, Main.EX.getActionListeners()[0], "All buttons should share the same listener");
120+
ActionListener zhListener = Main.huffmanCompressButton.getActionListeners()[0];
121+
assertSame(zhListener, Main.huffmanDecompressButton.getActionListeners()[0], "All buttons should share the same listener");
122+
assertSame(zhListener, Main.lzwCompressButton.getActionListeners()[0], "All buttons should share the same listener");
123+
assertSame(zhListener, Main.lzwDecompressButton.getActionListeners()[0], "All buttons should share the same listener");
124+
assertSame(zhListener, Main.exitButton.getActionListeners()[0], "All buttons should share the same listener");
125125
}
126126

127127
@Test

src/test/java/prog/huffman/HuffmanCompressionIntegrationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void testLargeFileCompression() throws IOException {
3838
System.out.println("Original file size: " + originalSize + " bytes");
3939

4040
// Compress the file
41-
Hzipping.beginHzipping(originalFile.getAbsolutePath());
41+
HuffmanCompressor.beginHuffmanCompression(originalFile.getAbsolutePath());
4242
assertTrue(compressedFile.exists(), "Compressed file should exist");
4343

4444
long compressedSize = Files.size(compressedFile.toPath());
@@ -50,7 +50,7 @@ void testLargeFileCompression() throws IOException {
5050
assertFalse(originalFile.exists(), "Original file should be deleted");
5151

5252
// Decompress
53-
Hunzipping.beginHunzipping(compressedFile.getAbsolutePath());
53+
HuffmanDecompressor.beginHuffmanDecompression(compressedFile.getAbsolutePath());
5454
assertTrue(decompressedFile.exists(), "Decompressed file should exist");
5555

5656
// Compare contents
@@ -92,15 +92,15 @@ private void testCompressionCycle(File testFile) throws IOException {
9292
String originalContent = Files.readString(testFile.toPath());
9393

9494
// Compress
95-
Hzipping.beginHzipping(testFile.getAbsolutePath());
95+
HuffmanCompressor.beginHuffmanCompression(testFile.getAbsolutePath());
9696
assertTrue(compressedFile.exists(), "Compressed file should exist");
9797

9898
// Delete original file
9999
Files.delete(testFile.toPath());
100100
assertFalse(testFile.exists(), "Original file should be deleted");
101101

102102
// Decompress
103-
Hunzipping.beginHunzipping(compressedFile.getAbsolutePath());
103+
HuffmanDecompressor.beginHuffmanDecompression(compressedFile.getAbsolutePath());
104104
assertTrue(decompressedFile.exists(), "Decompressed file should exist");
105105

106106
// Compare contents

src/test/java/prog/huffman/HzippingTest.java renamed to src/test/java/prog/huffman/HuffmanCompressorTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import static org.junit.jupiter.api.Assertions.*;
1515

16-
class HzippingTest {
16+
class HuffmanCompressorTest {
1717
@TempDir
1818
Path tempDir;
1919
private File inputFile;
@@ -31,7 +31,7 @@ void testEmptyFile() throws IOException {
3131
writer.write("");
3232
}
3333

34-
Hzipping.beginHzipping(inputFile.getAbsolutePath());
34+
HuffmanCompressor.beginHuffmanCompression(inputFile.getAbsolutePath());
3535
File compressedFile = new File(inputFile.getAbsolutePath() + ".huffz");
3636

3737
assertTrue(compressedFile.exists());
@@ -45,7 +45,7 @@ void testSingleCharacterFile() throws IOException {
4545
writer.write("aaaa");
4646
}
4747

48-
Hzipping.beginHzipping(inputFile.getAbsolutePath());
48+
HuffmanCompressor.beginHuffmanCompression(inputFile.getAbsolutePath());
4949
File compressedFile = new File(inputFile.getAbsolutePath() + ".huffz");
5050

5151
assertTrue(compressedFile.exists());
@@ -59,7 +59,7 @@ void testMultipleCharacterFile() throws IOException {
5959
writer.write("Hello, World! This is a test file with multiple characters.");
6060
}
6161

62-
Hzipping.beginHzipping(inputFile.getAbsolutePath());
62+
HuffmanCompressor.beginHuffmanCompression(inputFile.getAbsolutePath());
6363
File compressedFile = new File(inputFile.getAbsolutePath() + ".huffz");
6464

6565
assertTrue(compressedFile.exists());
@@ -74,21 +74,21 @@ void testFrequencyCalculation() throws IOException {
7474
writer.write("aabbc");
7575
}
7676

77-
Hzipping.initHzipping();
78-
Hzipping.CalFreq(inputFile.getAbsolutePath());
77+
HuffmanCompressor.initHuffmanCompressor();
78+
HuffmanCompressor.calculateFrequency(inputFile.getAbsolutePath());
7979

8080
// Check frequencies
81-
assertEquals(2, Hzipping.freq['a']);
82-
assertEquals(2, Hzipping.freq['b']);
83-
assertEquals(1, Hzipping.freq['c']);
81+
assertEquals(2, HuffmanCompressor.frequency['a']);
82+
assertEquals(2, HuffmanCompressor.frequency['b']);
83+
assertEquals(1, HuffmanCompressor.frequency['c']);
8484
}
8585

8686
@Test
8787
void testByteConversion() {
8888
// Test positive byte
89-
assertEquals(65, Hzipping.to((byte) 65)); // 'A'
89+
assertEquals(65, HuffmanCompressor.to((byte) 65)); // 'A'
9090
// Test negative byte
91-
assertEquals(128, Hzipping.to((byte) -128));
91+
assertEquals(128, HuffmanCompressor.to((byte) -128));
9292
}
9393

9494
@Test
@@ -98,24 +98,24 @@ void testTreeConstruction() throws IOException {
9898
writer.write("aabbc");
9999
}
100100

101-
Hzipping.initHzipping();
102-
Hzipping.CalFreq(inputFile.getAbsolutePath());
103-
Hzipping.MakeNode();
101+
HuffmanCompressor.initHuffmanCompressor();
102+
HuffmanCompressor.calculateFrequency(inputFile.getAbsolutePath());
103+
HuffmanCompressor.buildHuffmanTree();
104104

105105
// Verify tree construction
106-
assertNotNull(Hzipping.Root);
107-
assertEquals(5, Hzipping.Root.Freqnc); // Total frequency should be 5
106+
assertNotNull(HuffmanCompressor.root);
107+
assertEquals(5, HuffmanCompressor.root.frequency); // Total frequency should be 5
108108
}
109109

110110
@Test
111111
void testInitialization() {
112-
Hzipping.initHzipping();
112+
HuffmanCompressor.initHuffmanCompressor();
113113

114114
// Check if frequencies are reset
115-
assertTrue(Arrays.stream(Hzipping.freq).allMatch(freq -> freq == 0));
115+
assertTrue(Arrays.stream(HuffmanCompressor.frequency).allMatch(freq -> freq == 0));
116116
// Check if string array is reset
117-
assertTrue(Arrays.stream(Hzipping.ss).allMatch(s -> s.equals("")));
117+
assertTrue(Arrays.stream(HuffmanCompressor.huffmanCodes).allMatch(s -> s.equals("")));
118118
// Check if priority queue is empty
119-
assertTrue(Hzipping.pq.isEmpty());
119+
assertTrue(HuffmanCompressor.priorityQueue.isEmpty());
120120
}
121121
}

0 commit comments

Comments
 (0)