comparison graal/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugHistogramTest.java @ 21554:b1530a6cce8c

renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Tue, 26 May 2015 23:21:15 +0200
parents graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugHistogramTest.java@0ba1a6745070
children f5b549811bac
comparison
equal deleted inserted replaced
21553:0910a9497b02 21554:b1530a6cce8c
1 /*
2 * Copyright (c) 2013, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.jvmci.debug.test;
24
25 import java.io.*;
26
27 import org.junit.*;
28
29 import com.oracle.jvmci.debug.*;
30 import com.oracle.jvmci.debug.internal.*;
31
32
33 public class DebugHistogramTest {
34
35 @Test
36 public void testEmptyHistogram() {
37 DebugHistogram histogram = Debug.createHistogram("TestHistogram");
38 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
39
40 new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram);
41 String line = outputStream.toString().split("\r?\n")[0];
42 Assert.assertEquals("TestHistogram is empty.", line);
43
44 outputStream.reset();
45 new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram);
46 Assert.assertEquals("", outputStream.toString());
47 }
48
49 @Test
50 public void testSingleEntryHistogram() {
51 DebugHistogram histogram = Debug.createHistogram("TestHistogram");
52 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
53 histogram.add(new Integer(1));
54 histogram.add(new Integer(1));
55 new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram);
56 String[] lines = outputStream.toString().split("\r?\n");
57 // @formatter:off
58 String[] expected = {
59 "TestHistogram has 1 unique elements and 2 total elements:",
60 "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
61 "| 1 | 2 | ==================================================================================================== |",
62 "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
63 };
64 // @formatter:on
65 Assert.assertArrayEquals(expected, lines);
66
67 outputStream.reset();
68 new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram);
69 lines = outputStream.toString().split("\r?\n");
70 // @formatter:off
71 expected = new String[] {
72 "TestHistogram <- c(2);",
73 "names(TestHistogram) <- c(\"1\");"
74 };
75 // @formatter:on
76 Assert.assertArrayEquals(expected, lines);
77 }
78
79 @Test
80 public void testMultipleEntryHistogram() {
81 DebugHistogram histogram = Debug.createHistogram("TestHistogram");
82 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
83 histogram.add(new Integer(1));
84 histogram.add(new Integer(2));
85 histogram.add(new Integer(2));
86 new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram);
87 String[] lines = outputStream.toString().split("\r?\n");
88 // @formatter:off
89 String[] expected = new String[] {
90 "TestHistogram has 2 unique elements and 3 total elements:",
91 "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
92 "| 2 | 2 | ==================================================================================================== |",
93 "| 1 | 1 | ================================================== |",
94 "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
95 };
96 // @formatter:on
97 Assert.assertArrayEquals(expected, lines);
98
99 outputStream.reset();
100 new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram);
101 lines = outputStream.toString().split("\r?\n");
102 // @formatter:off
103 expected = new String[] {
104 "TestHistogram <- c(2, 1);",
105 "names(TestHistogram) <- c(\"2\", \"1\");"
106 };
107 // @formatter:on
108 Assert.assertArrayEquals(expected, lines);
109 }
110
111 @Test
112 public void testTooLongValueString() {
113 DebugHistogram histogram = Debug.createHistogram("TestHistogram");
114 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
115 histogram.add("MyCustomValue");
116 new DebugHistogramAsciiPrinter(new PrintStream(outputStream), Integer.MAX_VALUE, 10, 10, 1).print(histogram);
117 String[] lines = outputStream.toString().split("\r?\n");
118 Assert.assertEquals(4, lines.length);
119 Assert.assertEquals("TestHistogram has 1 unique elements and 1 total elements:", lines[0]);
120 Assert.assertEquals("----------------------------------------", lines[1]);
121 Assert.assertEquals("| MyCusto... | 1 | ========== |", lines[2]);
122 Assert.assertEquals("----------------------------------------", lines[3]);
123 }
124 }