1 | package de.uka.ipd.sdq.sensorframework.storage.tests; |
2 | |
3 | import java.io.File; |
4 | import java.io.IOException; |
5 | |
6 | import junit.framework.Assert; |
7 | import junit.framework.TestCase; |
8 | import de.uka.ipd.sdq.sensorframework.storage.lists.BackgroundMemoryList; |
9 | import de.uka.ipd.sdq.sensorframework.storage.lists.DoubleSerialiser; |
10 | |
11 | |
12 | public class DoubleListTest extends TestCase { |
13 | |
14 | private static final int LARGE_LIST_TEST_COUNT = 1000000; |
15 | |
16 | public void testList() { |
17 | BackgroundMemoryList<Double> list; |
18 | try { |
19 | File tempFile = File.createTempFile("TempDB", "lst"); |
20 | list = new BackgroundMemoryList<Double>(tempFile.getAbsolutePath(), |
21 | new DoubleSerialiser()); |
22 | list.add(1.0); |
23 | list.close(); |
24 | Assert.assertEquals(8, tempFile.length()); |
25 | |
26 | list = new BackgroundMemoryList<Double>(tempFile.getAbsolutePath(), |
27 | new DoubleSerialiser()); |
28 | Assert.assertEquals(1,list.size()); |
29 | Assert.assertEquals(1.0, list.get(0)); |
30 | list.add(2.0); |
31 | Assert.assertEquals(2,list.size()); |
32 | Assert.assertEquals(2.0, list.get(1)); |
33 | list.close(); |
34 | Assert.assertEquals(16, tempFile.length()); |
35 | |
36 | } catch (IOException e) { |
37 | e.printStackTrace(); |
38 | Assert.assertTrue(false); |
39 | } |
40 | } |
41 | |
42 | public void testList2() { |
43 | BackgroundMemoryList<Double> list; |
44 | try { |
45 | File tempFile = File.createTempFile("TempDB", "lst"); |
46 | list = new BackgroundMemoryList<Double>(tempFile.getAbsolutePath(), |
47 | new DoubleSerialiser()); |
48 | for (double i = 0; i < LARGE_LIST_TEST_COUNT; i += 1) |
49 | list.add(i); |
50 | list.close(); |
51 | Assert.assertEquals(LARGE_LIST_TEST_COUNT * 8, tempFile.length()); |
52 | |
53 | list = new BackgroundMemoryList<Double>(tempFile.getAbsolutePath(), |
54 | new DoubleSerialiser()); |
55 | for (double i = 0; i < LARGE_LIST_TEST_COUNT; i += 1) |
56 | Assert.assertEquals(i,list.get((int)i)); |
57 | list.close(); |
58 | } catch (IOException e) { |
59 | e.printStackTrace(); |
60 | Assert.assertTrue(false); |
61 | } |
62 | } |
63 | |
64 | } |