comparison jvmci/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugHistogramTest.java @ 21798:395ac43a8578

moved JVMCI sources from graal/ to jvmci/ directory
author Doug Simon <doug.simon@oracle.com>
date Tue, 09 Jun 2015 00:22:49 +0200
parents graal/com.oracle.jvmci.debug.test/src/com/oracle/jvmci/debug/test/DebugHistogramTest.java@f5b549811bac
children
comparison
equal deleted inserted replaced
21797:42452d2dfbec 21798:395ac43a8578
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 public class DebugHistogramTest {
33
34 @Test
35 public void testEmptyHistogram() {
36 DebugHistogram histogram = Debug.createHistogram("TestHistogram");
37 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
38
39 new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram);
40 String line = outputStream.toString().split("\r?\n")[0];
41 Assert.assertEquals("TestHistogram is empty.", line);
42
43 outputStream.reset();
44 new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram);
45 Assert.assertEquals("", outputStream.toString());
46 }
47
48 @Test
49 public void testSingleEntryHistogram() {
50 DebugHistogram histogram = Debug.createHistogram("TestHistogram");
51 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
52 histogram.add(new Integer(1));
53 histogram.add(new Integer(1));
54 new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram);
55 String[] lines = outputStream.toString().split("\r?\n");
56 // @formatter:off
57 String[] expected = {
58 "TestHistogram has 1 unique elements and 2 total elements:",
59 "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
60 "| 1 | 2 | ==================================================================================================== |",
61 "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
62 };
63 // @formatter:on
64 Assert.assertArrayEquals(expected, lines);
65
66 outputStream.reset();
67 new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram);
68 lines = outputStream.toString().split("\r?\n");
69 // @formatter:off
70 expected = new String[] {
71 "TestHistogram <- c(2);",
72 "names(TestHistogram) <- c(\"1\");"
73 };
74 // @formatter:on
75 Assert.assertArrayEquals(expected, lines);
76 }
77
78 @Test
79 public void testMultipleEntryHistogram() {
80 DebugHistogram histogram = Debug.createHistogram("TestHistogram");
81 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
82 histogram.add(new Integer(1));
83 histogram.add(new Integer(2));
84 histogram.add(new Integer(2));
85 new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram);
86 String[] lines = outputStream.toString().split("\r?\n");
87 // @formatter:off
88 String[] expected = new String[] {
89 "TestHistogram has 2 unique elements and 3 total elements:",
90 "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
91 "| 2 | 2 | ==================================================================================================== |",
92 "| 1 | 1 | ================================================== |",
93 "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
94 };
95 // @formatter:on
96 Assert.assertArrayEquals(expected, lines);
97
98 outputStream.reset();
99 new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram);
100 lines = outputStream.toString().split("\r?\n");
101 // @formatter:off
102 expected = new String[] {
103 "TestHistogram <- c(2, 1);",
104 "names(TestHistogram) <- c(\"2\", \"1\");"
105 };
106 // @formatter:on
107 Assert.assertArrayEquals(expected, lines);
108 }
109
110 @Test
111 public void testTooLongValueString() {
112 DebugHistogram histogram = Debug.createHistogram("TestHistogram");
113 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
114 histogram.add("MyCustomValue");
115 new DebugHistogramAsciiPrinter(new PrintStream(outputStream), Integer.MAX_VALUE, 10, 10, 1).print(histogram);
116 String[] lines = outputStream.toString().split("\r?\n");
117 Assert.assertEquals(4, lines.length);
118 Assert.assertEquals("TestHistogram has 1 unique elements and 1 total elements:", lines[0]);
119 Assert.assertEquals("----------------------------------------", lines[1]);
120 Assert.assertEquals("| MyCusto... | 1 | ========== |", lines[2]);
121 Assert.assertEquals("----------------------------------------", lines[3]);
122 }
123 }