How to use format method of junit.framework.Assert class

Best junit code snippet using junit.framework.Assert.format

Source:RealVectorFormatAbstractTest.java Github

copy

Full Screen

...13 }14 public void testSimpleNoDecimals() {15 org.apache.commons.math.linear.ArrayRealVector c = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1 , 1 , 1 });16 java.lang.String expected = "{1; 1; 1}";17 java.lang.String actual = realVectorFormat.format(c);18 junit.framework.Assert.assertEquals(expected, actual);19 }20 public void testSimpleWithDecimals() {21 org.apache.commons.math.linear.ArrayRealVector c = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1.23 , 1.43 , 1.63 });22 java.lang.String expected = ((((("{1" + (getDecimalCharacter())) + "23; 1") + (getDecimalCharacter())) + "43; 1") + (getDecimalCharacter())) + "63}";23 java.lang.String actual = realVectorFormat.format(c);24 junit.framework.Assert.assertEquals(expected, actual);25 }26 public void testSimpleWithDecimalsTrunc() {27 org.apache.commons.math.linear.ArrayRealVector c = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1.2323 , 1.4343 , 1.6333 });28 java.lang.String expected = ((((("{1" + (getDecimalCharacter())) + "23; 1") + (getDecimalCharacter())) + "43; 1") + (getDecimalCharacter())) + "63}";29 java.lang.String actual = realVectorFormat.format(c);30 junit.framework.Assert.assertEquals(expected, actual);31 }32 public void testNegativeX() {33 org.apache.commons.math.linear.ArrayRealVector c = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ -1.2323 , 1.4343 , 1.6333 });34 java.lang.String expected = ((((("{-1" + (getDecimalCharacter())) + "23; 1") + (getDecimalCharacter())) + "43; 1") + (getDecimalCharacter())) + "63}";35 java.lang.String actual = realVectorFormat.format(c);36 junit.framework.Assert.assertEquals(expected, actual);37 }38 public void testNegativeY() {39 org.apache.commons.math.linear.ArrayRealVector c = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1.2323 , -1.4343 , 1.6333 });40 java.lang.String expected = ((((("{1" + (getDecimalCharacter())) + "23; -1") + (getDecimalCharacter())) + "43; 1") + (getDecimalCharacter())) + "63}";41 java.lang.String actual = realVectorFormat.format(c);42 junit.framework.Assert.assertEquals(expected, actual);43 }44 public void testNegativeZ() {45 org.apache.commons.math.linear.ArrayRealVector c = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1.2323 , 1.4343 , -1.6333 });46 java.lang.String expected = ((((("{1" + (getDecimalCharacter())) + "23; 1") + (getDecimalCharacter())) + "43; -1") + (getDecimalCharacter())) + "63}";47 java.lang.String actual = realVectorFormat.format(c);48 junit.framework.Assert.assertEquals(expected, actual);49 }50 public void testNonDefaultSetting() {51 org.apache.commons.math.linear.ArrayRealVector c = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1 , 1 , 1 });52 java.lang.String expected = "[1 : 1 : 1]";53 java.lang.String actual = realVectorFormatSquare.format(c);54 junit.framework.Assert.assertEquals(expected, actual);55 }56 public void testStaticFormatRealVectorImpl() {57 java.util.Locale defaultLocal = java.util.Locale.getDefault();58 java.util.Locale.setDefault(getLocale());59 org.apache.commons.math.linear.ArrayRealVector c = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 232.222 , -342.33 , 432.444 });60 java.lang.String expected = ((((("{232" + (getDecimalCharacter())) + "22; -342") + (getDecimalCharacter())) + "33; 432") + (getDecimalCharacter())) + "44}";61 java.lang.String actual = org.apache.commons.math.linear.RealVectorFormat.formatRealVector(c);62 junit.framework.Assert.assertEquals(expected, actual);63 java.util.Locale.setDefault(defaultLocal);64 }65 public void testNan() {66 org.apache.commons.math.linear.ArrayRealVector c = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ java.lang.Double.NaN , java.lang.Double.NaN , java.lang.Double.NaN });67 java.lang.String expected = "{(NaN); (NaN); (NaN)}";68 java.lang.String actual = realVectorFormat.format(c);69 junit.framework.Assert.assertEquals(expected, actual);70 }71 public void testPositiveInfinity() {72 org.apache.commons.math.linear.ArrayRealVector c = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ java.lang.Double.POSITIVE_INFINITY , java.lang.Double.POSITIVE_INFINITY , java.lang.Double.POSITIVE_INFINITY });73 java.lang.String expected = "{(Infinity); (Infinity); (Infinity)}";74 java.lang.String actual = realVectorFormat.format(c);75 junit.framework.Assert.assertEquals(expected, actual);76 }77 public void tesNegativeInfinity() {78 org.apache.commons.math.linear.ArrayRealVector c = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ java.lang.Double.NEGATIVE_INFINITY , java.lang.Double.NEGATIVE_INFINITY , java.lang.Double.NEGATIVE_INFINITY });79 java.lang.String expected = "{(-Infinity); (-Infinity); (-Infinity)}";80 java.lang.String actual = realVectorFormat.format(c);81 junit.framework.Assert.assertEquals(expected, actual);82 }83 public void testParseSimpleNoDecimals() {84 java.lang.String source = "{1; 1; 1}";85 org.apache.commons.math.linear.ArrayRealVector expected = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1 , 1 , 1 });86 try {87 org.apache.commons.math.linear.ArrayRealVector actual = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormat.parseObject(source)));88 junit.framework.Assert.assertEquals(expected, actual);89 } catch (java.text.ParseException ex) {90 junit.framework.Assert.fail(ex.getMessage());91 }92 }93 public void testParseIgnoredWhitespace() {94 org.apache.commons.math.linear.ArrayRealVector expected = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1 , 1 , 1 });95 java.text.ParsePosition pos1 = new java.text.ParsePosition(0);96 java.lang.String source1 = "{1;1;1}";97 junit.framework.Assert.assertEquals(expected, realVectorFormat.parseObject(source1, pos1));98 junit.framework.Assert.assertEquals(source1.length(), pos1.getIndex());99 java.text.ParsePosition pos2 = new java.text.ParsePosition(0);100 java.lang.String source2 = " { 1 ; 1 ; 1 } ";101 junit.framework.Assert.assertEquals(expected, realVectorFormat.parseObject(source2, pos2));102 junit.framework.Assert.assertEquals(((source2.length()) - 1), pos2.getIndex());103 }104 public void testParseSimpleWithDecimals() {105 java.lang.String source = ((((("{1" + (getDecimalCharacter())) + "23; 1") + (getDecimalCharacter())) + "43; 1") + (getDecimalCharacter())) + "63}";106 org.apache.commons.math.linear.ArrayRealVector expected = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1.23 , 1.43 , 1.63 });107 try {108 org.apache.commons.math.linear.ArrayRealVector actual = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormat.parseObject(source)));109 junit.framework.Assert.assertEquals(expected, actual);110 } catch (java.text.ParseException ex) {111 junit.framework.Assert.fail(ex.getMessage());112 }113 }114 public void testParseSimpleWithDecimalsTrunc() {115 java.lang.String source = ((((("{1" + (getDecimalCharacter())) + "2323; 1") + (getDecimalCharacter())) + "4343; 1") + (getDecimalCharacter())) + "6333}";116 org.apache.commons.math.linear.ArrayRealVector expected = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1.2323 , 1.4343 , 1.6333 });117 try {118 org.apache.commons.math.linear.ArrayRealVector actual = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormat.parseObject(source)));119 junit.framework.Assert.assertEquals(expected, actual);120 } catch (java.text.ParseException ex) {121 junit.framework.Assert.fail(ex.getMessage());122 }123 }124 public void testParseNegativeX() {125 java.lang.String source = ((((("{-1" + (getDecimalCharacter())) + "2323; 1") + (getDecimalCharacter())) + "4343; 1") + (getDecimalCharacter())) + "6333}";126 org.apache.commons.math.linear.ArrayRealVector expected = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ -1.2323 , 1.4343 , 1.6333 });127 try {128 org.apache.commons.math.linear.ArrayRealVector actual = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormat.parseObject(source)));129 junit.framework.Assert.assertEquals(expected, actual);130 } catch (java.text.ParseException ex) {131 junit.framework.Assert.fail(ex.getMessage());132 }133 }134 public void testParseNegativeY() {135 java.lang.String source = ((((("{1" + (getDecimalCharacter())) + "2323; -1") + (getDecimalCharacter())) + "4343; 1") + (getDecimalCharacter())) + "6333}";136 org.apache.commons.math.linear.ArrayRealVector expected = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1.2323 , -1.4343 , 1.6333 });137 try {138 org.apache.commons.math.linear.ArrayRealVector actual = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormat.parseObject(source)));139 junit.framework.Assert.assertEquals(expected, actual);140 } catch (java.text.ParseException ex) {141 junit.framework.Assert.fail(ex.getMessage());142 }143 }144 public void testParseNegativeZ() {145 java.lang.String source = ((((("{1" + (getDecimalCharacter())) + "2323; 1") + (getDecimalCharacter())) + "4343; -1") + (getDecimalCharacter())) + "6333}";146 org.apache.commons.math.linear.ArrayRealVector expected = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1.2323 , 1.4343 , -1.6333 });147 try {148 org.apache.commons.math.linear.ArrayRealVector actual = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormat.parseObject(source)));149 junit.framework.Assert.assertEquals(expected, actual);150 } catch (java.text.ParseException ex) {151 junit.framework.Assert.fail(ex.getMessage());152 }153 }154 public void testParseNegativeAll() {155 java.lang.String source = ((((("{-1" + (getDecimalCharacter())) + "2323; -1") + (getDecimalCharacter())) + "4343; -1") + (getDecimalCharacter())) + "6333}";156 org.apache.commons.math.linear.ArrayRealVector expected = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ -1.2323 , -1.4343 , -1.6333 });157 try {158 org.apache.commons.math.linear.ArrayRealVector actual = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormat.parseObject(source)));159 junit.framework.Assert.assertEquals(expected, actual);160 } catch (java.text.ParseException ex) {161 junit.framework.Assert.fail(ex.getMessage());162 }163 }164 public void testParseZeroX() {165 java.lang.String source = ((((("{0" + (getDecimalCharacter())) + "0; -1") + (getDecimalCharacter())) + "4343; 1") + (getDecimalCharacter())) + "6333}";166 org.apache.commons.math.linear.ArrayRealVector expected = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 0.0 , -1.4343 , 1.6333 });167 try {168 org.apache.commons.math.linear.ArrayRealVector actual = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormat.parseObject(source)));169 junit.framework.Assert.assertEquals(expected, actual);170 } catch (java.text.ParseException ex) {171 junit.framework.Assert.fail(ex.getMessage());172 }173 }174 public void testParseNonDefaultSetting() {175 java.lang.String source = ((((("[1" + (getDecimalCharacter())) + "2323 : 1") + (getDecimalCharacter())) + "4343 : 1") + (getDecimalCharacter())) + "6333]";176 org.apache.commons.math.linear.ArrayRealVector expected = new org.apache.commons.math.linear.ArrayRealVector(new double[]{ 1.2323 , 1.4343 , 1.6333 });177 try {178 org.apache.commons.math.linear.ArrayRealVector actual = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormatSquare.parseObject(source)));179 junit.framework.Assert.assertEquals(expected, actual);180 } catch (java.text.ParseException ex) {181 junit.framework.Assert.fail(ex.getMessage());182 }183 }184 public void testParseNan() {185 java.lang.String source = "{(NaN); (NaN); (NaN)}";186 try {187 org.apache.commons.math.linear.ArrayRealVector actual = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormat.parseObject(source)));188 junit.framework.Assert.assertEquals(new org.apache.commons.math.linear.ArrayRealVector(new double[]{ java.lang.Double.NaN , java.lang.Double.NaN , java.lang.Double.NaN }), actual);189 } catch (java.text.ParseException ex) {190 junit.framework.Assert.fail(ex.getMessage());191 }192 }193 public void testParsePositiveInfinity() {194 java.lang.String source = "{(Infinity); (Infinity); (Infinity)}";195 try {196 org.apache.commons.math.linear.ArrayRealVector actual = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormat.parseObject(source)));197 junit.framework.Assert.assertEquals(new org.apache.commons.math.linear.ArrayRealVector(new double[]{ java.lang.Double.POSITIVE_INFINITY , java.lang.Double.POSITIVE_INFINITY , java.lang.Double.POSITIVE_INFINITY }), actual);198 } catch (java.text.ParseException ex) {199 junit.framework.Assert.fail(ex.getMessage());200 }201 }202 public void testParseNegativeInfinity() {203 java.lang.String source = "{(-Infinity); (-Infinity); (-Infinity)}";204 try {205 org.apache.commons.math.linear.ArrayRealVector actual = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormat.parseObject(source)));206 junit.framework.Assert.assertEquals(new org.apache.commons.math.linear.ArrayRealVector(new double[]{ java.lang.Double.NEGATIVE_INFINITY , java.lang.Double.NEGATIVE_INFINITY , java.lang.Double.NEGATIVE_INFINITY }), actual);207 } catch (java.text.ParseException ex) {208 junit.framework.Assert.fail(ex.getMessage());209 }210 }211 public void testParseNoComponents() {212 try {213 realVectorFormat.parseObject("{ }");214 } catch (java.text.ParseException pe) {215 } catch (java.lang.Exception e) {216 junit.framework.Assert.fail("wrong exception caught");217 }218 }219 public void testParseManyComponents() throws java.text.ParseException {220 org.apache.commons.math.linear.ArrayRealVector parsed = ((org.apache.commons.math.linear.ArrayRealVector)(realVectorFormat.parseObject("{0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0}")));221 junit.framework.Assert.assertEquals(24, parsed.getDimension());222 }223 public void testConstructorSingleFormat() {224 java.text.NumberFormat nf = java.text.NumberFormat.getInstance();225 org.apache.commons.math.linear.RealVectorFormat cf = new org.apache.commons.math.linear.RealVectorFormat(nf);226 junit.framework.Assert.assertNotNull(cf);227 junit.framework.Assert.assertEquals(nf, cf.getFormat());228 }229 public void testFormatObject() {230 try {231 org.apache.commons.math.util.CompositeFormat cf = new org.apache.commons.math.linear.RealVectorFormat();232 java.lang.Object object = new java.lang.Object();233 cf.format(object);234 junit.framework.Assert.fail();235 } catch (java.lang.IllegalArgumentException ex) {236 }237 }238 public void testForgottenPrefix() {239 java.text.ParsePosition pos = new java.text.ParsePosition(0);240 final java.lang.String source = "1; 1; 1}";241 junit.framework.Assert.assertNull((("Should not parse <" + source) + ">"), new org.apache.commons.math.linear.RealVectorFormat().parse(source, pos));242 junit.framework.Assert.assertEquals(0, pos.getErrorIndex());243 }244 public void testForgottenSeparator() {245 java.text.ParsePosition pos = new java.text.ParsePosition(0);246 final java.lang.String source = "{1; 1 1}";247 junit.framework.Assert.assertNull((("Should not parse <" + source) + ">"), new org.apache.commons.math.linear.RealVectorFormat().parse(source, pos));...

Full Screen

Full Screen

Source:ComplexFormatAbstractTest.java Github

copy

Full Screen

...12 }13 public void testSimpleNoDecimals() {14 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(1 , 1);15 java.lang.String expected = "1 + 1i";16 java.lang.String actual = complexFormat.format(c);17 junit.framework.Assert.assertEquals(expected, actual);18 }19 public void testSimpleWithDecimals() {20 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(1.23 , 1.43);21 java.lang.String expected = ((("1" + (getDecimalCharacter())) + "23 + 1") + (getDecimalCharacter())) + "43i";22 java.lang.String actual = complexFormat.format(c);23 junit.framework.Assert.assertEquals(expected, actual);24 }25 public void testSimpleWithDecimalsTrunc() {26 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(1.2323 , 1.4343);27 java.lang.String expected = ((("1" + (getDecimalCharacter())) + "23 + 1") + (getDecimalCharacter())) + "43i";28 java.lang.String actual = complexFormat.format(c);29 junit.framework.Assert.assertEquals(expected, actual);30 }31 public void testNegativeReal() {32 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(-1.2323 , 1.4343);33 java.lang.String expected = ((("-1" + (getDecimalCharacter())) + "23 + 1") + (getDecimalCharacter())) + "43i";34 java.lang.String actual = complexFormat.format(c);35 junit.framework.Assert.assertEquals(expected, actual);36 }37 public void testNegativeImaginary() {38 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(1.2323 , -1.4343);39 java.lang.String expected = ((("1" + (getDecimalCharacter())) + "23 - 1") + (getDecimalCharacter())) + "43i";40 java.lang.String actual = complexFormat.format(c);41 junit.framework.Assert.assertEquals(expected, actual);42 }43 public void testNegativeBoth() {44 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(-1.2323 , -1.4343);45 java.lang.String expected = ((("-1" + (getDecimalCharacter())) + "23 - 1") + (getDecimalCharacter())) + "43i";46 java.lang.String actual = complexFormat.format(c);47 junit.framework.Assert.assertEquals(expected, actual);48 }49 public void testZeroReal() {50 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(0.0 , -1.4343);51 java.lang.String expected = ("0 - 1" + (getDecimalCharacter())) + "43i";52 java.lang.String actual = complexFormat.format(c);53 junit.framework.Assert.assertEquals(expected, actual);54 }55 public void testZeroImaginary() {56 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(30.233 , 0);57 java.lang.String expected = ("30" + (getDecimalCharacter())) + "23";58 java.lang.String actual = complexFormat.format(c);59 junit.framework.Assert.assertEquals(expected, actual);60 }61 public void testDifferentImaginaryChar() {62 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(1 , 1);63 java.lang.String expected = "1 + 1j";64 java.lang.String actual = complexFormatJ.format(c);65 junit.framework.Assert.assertEquals(expected, actual);66 }67 public void testStaticFormatComplex() {68 java.util.Locale defaultLocal = java.util.Locale.getDefault();69 java.util.Locale.setDefault(getLocale());70 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(232.222 , -342.33);71 java.lang.String expected = ((("232" + (getDecimalCharacter())) + "22 - 342") + (getDecimalCharacter())) + "33i";72 java.lang.String actual = org.apache.commons.math.complex.ComplexFormat.formatComplex(c);73 junit.framework.Assert.assertEquals(expected, actual);74 java.util.Locale.setDefault(defaultLocal);75 }76 public void testNan() {77 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(java.lang.Double.NaN , java.lang.Double.NaN);78 java.lang.String expected = "(NaN) + (NaN)i";79 java.lang.String actual = complexFormat.format(c);80 junit.framework.Assert.assertEquals(expected, actual);81 }82 public void testPositiveInfinity() {83 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(java.lang.Double.POSITIVE_INFINITY , java.lang.Double.POSITIVE_INFINITY);84 java.lang.String expected = "(Infinity) + (Infinity)i";85 java.lang.String actual = complexFormat.format(c);86 junit.framework.Assert.assertEquals(expected, actual);87 }88 public void testNegativeInfinity() {89 org.apache.commons.math.complex.Complex c = new org.apache.commons.math.complex.Complex(java.lang.Double.NEGATIVE_INFINITY , java.lang.Double.NEGATIVE_INFINITY);90 java.lang.String expected = "(-Infinity) - (Infinity)i";91 java.lang.String actual = complexFormat.format(c);92 junit.framework.Assert.assertEquals(expected, actual);93 }94 public void testParseSimpleNoDecimals() {95 java.lang.String source = "1 + 1i";96 org.apache.commons.math.complex.Complex expected = new org.apache.commons.math.complex.Complex(1 , 1);97 try {98 org.apache.commons.math.complex.Complex actual = ((org.apache.commons.math.complex.Complex)(complexFormat.parseObject(source)));99 junit.framework.Assert.assertEquals(expected, actual);100 } catch (java.text.ParseException ex) {101 junit.framework.Assert.fail(ex.getMessage());102 }103 }104 public void testParseSimpleWithDecimals() {105 java.lang.String source = ((("1" + (getDecimalCharacter())) + "23 + 1") + (getDecimalCharacter())) + "43i";106 org.apache.commons.math.complex.Complex expected = new org.apache.commons.math.complex.Complex(1.23 , 1.43);107 try {108 org.apache.commons.math.complex.Complex actual = ((org.apache.commons.math.complex.Complex)(complexFormat.parseObject(source)));109 junit.framework.Assert.assertEquals(expected, actual);110 } catch (java.text.ParseException ex) {111 junit.framework.Assert.fail(ex.getMessage());112 }113 }114 public void testParseSimpleWithDecimalsTrunc() {115 java.lang.String source = ((("1" + (getDecimalCharacter())) + "2323 + 1") + (getDecimalCharacter())) + "4343i";116 org.apache.commons.math.complex.Complex expected = new org.apache.commons.math.complex.Complex(1.2323 , 1.4343);117 try {118 org.apache.commons.math.complex.Complex actual = ((org.apache.commons.math.complex.Complex)(complexFormat.parseObject(source)));119 junit.framework.Assert.assertEquals(expected, actual);120 } catch (java.text.ParseException ex) {121 junit.framework.Assert.fail(ex.getMessage());122 }123 }124 public void testParseNegativeReal() {125 java.lang.String source = ((("-1" + (getDecimalCharacter())) + "2323 + 1") + (getDecimalCharacter())) + "4343i";126 org.apache.commons.math.complex.Complex expected = new org.apache.commons.math.complex.Complex(-1.2323 , 1.4343);127 try {128 org.apache.commons.math.complex.Complex actual = ((org.apache.commons.math.complex.Complex)(complexFormat.parseObject(source)));129 junit.framework.Assert.assertEquals(expected, actual);130 } catch (java.text.ParseException ex) {131 junit.framework.Assert.fail(ex.getMessage());132 }133 }134 public void testParseNegativeImaginary() {135 java.lang.String source = ((("1" + (getDecimalCharacter())) + "2323 - 1") + (getDecimalCharacter())) + "4343i";136 org.apache.commons.math.complex.Complex expected = new org.apache.commons.math.complex.Complex(1.2323 , -1.4343);137 try {138 org.apache.commons.math.complex.Complex actual = ((org.apache.commons.math.complex.Complex)(complexFormat.parseObject(source)));139 junit.framework.Assert.assertEquals(expected, actual);140 } catch (java.text.ParseException ex) {141 junit.framework.Assert.fail(ex.getMessage());142 }143 }144 public void testParseNegativeBoth() {145 java.lang.String source = ((("-1" + (getDecimalCharacter())) + "2323 - 1") + (getDecimalCharacter())) + "4343i";146 org.apache.commons.math.complex.Complex expected = new org.apache.commons.math.complex.Complex(-1.2323 , -1.4343);147 try {148 org.apache.commons.math.complex.Complex actual = ((org.apache.commons.math.complex.Complex)(complexFormat.parseObject(source)));149 junit.framework.Assert.assertEquals(expected, actual);150 } catch (java.text.ParseException ex) {151 junit.framework.Assert.fail(ex.getMessage());152 }153 }154 public void testParseZeroReal() {155 java.lang.String source = ((("0" + (getDecimalCharacter())) + "0 - 1") + (getDecimalCharacter())) + "4343i";156 org.apache.commons.math.complex.Complex expected = new org.apache.commons.math.complex.Complex(0.0 , -1.4343);157 try {158 org.apache.commons.math.complex.Complex actual = ((org.apache.commons.math.complex.Complex)(complexFormat.parseObject(source)));159 junit.framework.Assert.assertEquals(expected, actual);160 } catch (java.text.ParseException ex) {161 junit.framework.Assert.fail(ex.getMessage());162 }163 }164 public void testParseZeroImaginary() {165 java.lang.String source = ("-1" + (getDecimalCharacter())) + "2323";166 org.apache.commons.math.complex.Complex expected = new org.apache.commons.math.complex.Complex(-1.2323 , 0);167 try {168 org.apache.commons.math.complex.Complex actual = ((org.apache.commons.math.complex.Complex)(complexFormat.parseObject(source)));169 junit.framework.Assert.assertEquals(expected, actual);170 } catch (java.text.ParseException ex) {171 junit.framework.Assert.fail(ex.getMessage());172 }173 }174 public void testParseDifferentImaginaryChar() {175 java.lang.String source = ((("-1" + (getDecimalCharacter())) + "2323 - 1") + (getDecimalCharacter())) + "4343j";176 org.apache.commons.math.complex.Complex expected = new org.apache.commons.math.complex.Complex(-1.2323 , -1.4343);177 try {178 org.apache.commons.math.complex.Complex actual = ((org.apache.commons.math.complex.Complex)(complexFormatJ.parseObject(source)));179 junit.framework.Assert.assertEquals(expected, actual);180 } catch (java.text.ParseException ex) {181 junit.framework.Assert.fail(ex.getMessage());182 }183 }184 public void testParseNan() {185 java.lang.String source = "(NaN) + (NaN)i";186 org.apache.commons.math.complex.Complex expected = new org.apache.commons.math.complex.Complex(java.lang.Double.NaN , java.lang.Double.NaN);187 try {188 org.apache.commons.math.complex.Complex actual = ((org.apache.commons.math.complex.Complex)(complexFormat.parseObject(source)));189 junit.framework.Assert.assertEquals(expected, actual);190 } catch (java.text.ParseException ex) {191 junit.framework.Assert.fail(ex.getMessage());192 }193 }194 public void testParsePositiveInfinity() {195 java.lang.String source = "(Infinity) + (Infinity)i";196 org.apache.commons.math.complex.Complex expected = new org.apache.commons.math.complex.Complex(java.lang.Double.POSITIVE_INFINITY , java.lang.Double.POSITIVE_INFINITY);197 try {198 org.apache.commons.math.complex.Complex actual = ((org.apache.commons.math.complex.Complex)(complexFormat.parseObject(source)));199 junit.framework.Assert.assertEquals(expected, actual);200 } catch (java.text.ParseException ex) {201 junit.framework.Assert.fail(ex.getMessage());202 }203 }204 public void testPaseNegativeInfinity() {205 java.lang.String source = "(-Infinity) - (Infinity)i";206 org.apache.commons.math.complex.Complex expected = new org.apache.commons.math.complex.Complex(java.lang.Double.NEGATIVE_INFINITY , java.lang.Double.NEGATIVE_INFINITY);207 try {208 org.apache.commons.math.complex.Complex actual = ((org.apache.commons.math.complex.Complex)(complexFormat.parseObject(source)));209 junit.framework.Assert.assertEquals(expected, actual);210 } catch (java.text.ParseException ex) {211 junit.framework.Assert.fail(ex.getMessage());212 }213 }214 public void testConstructorSingleFormat() {215 java.text.NumberFormat nf = java.text.NumberFormat.getInstance();216 org.apache.commons.math.complex.ComplexFormat cf = new org.apache.commons.math.complex.ComplexFormat(nf);217 junit.framework.Assert.assertNotNull(cf);218 junit.framework.Assert.assertEquals(nf, cf.getRealFormat());219 }220 public void testGetImaginaryFormat() {221 java.text.NumberFormat nf = java.text.NumberFormat.getInstance();222 org.apache.commons.math.complex.ComplexFormat cf = new org.apache.commons.math.complex.ComplexFormat();223 junit.framework.Assert.assertNotSame(nf, cf.getImaginaryFormat());224 cf.setImaginaryFormat(nf);225 junit.framework.Assert.assertSame(nf, cf.getImaginaryFormat());226 }227 public void testSetImaginaryFormatNull() {228 try {229 org.apache.commons.math.complex.ComplexFormat cf = new org.apache.commons.math.complex.ComplexFormat();230 cf.setImaginaryFormat(null);231 junit.framework.Assert.fail();232 } catch (java.lang.IllegalArgumentException ex) {233 }234 }235 public void testSetRealFormatNull() {236 try {237 org.apache.commons.math.complex.ComplexFormat cf = new org.apache.commons.math.complex.ComplexFormat();238 cf.setRealFormat(null);239 junit.framework.Assert.fail();240 } catch (java.lang.IllegalArgumentException ex) {241 }242 }243 public void testGetRealFormat() {244 java.text.NumberFormat nf = java.text.NumberFormat.getInstance();245 org.apache.commons.math.complex.ComplexFormat cf = new org.apache.commons.math.complex.ComplexFormat();246 junit.framework.Assert.assertNotSame(nf, cf.getRealFormat());247 cf.setRealFormat(nf);248 junit.framework.Assert.assertSame(nf, cf.getRealFormat());249 }250 public void testSetImaginaryCharacterNull() {251 try {252 org.apache.commons.math.complex.ComplexFormat cf = new org.apache.commons.math.complex.ComplexFormat();253 cf.setImaginaryCharacter(null);254 junit.framework.Assert.fail();255 } catch (java.lang.IllegalArgumentException ex) {256 }257 }258 public void testSetImaginaryCharacterEmpty() {259 try {260 org.apache.commons.math.complex.ComplexFormat cf = new org.apache.commons.math.complex.ComplexFormat();261 cf.setImaginaryCharacter("");262 junit.framework.Assert.fail();263 } catch (java.lang.IllegalArgumentException ex) {264 }265 }266 public void testFormatNumber() {267 org.apache.commons.math.util.CompositeFormat cf = org.apache.commons.math.complex.ComplexFormat.getInstance(getLocale());268 java.lang.Double pi = java.lang.Double.valueOf(java.lang.Math.PI);269 java.lang.String text = cf.format(pi);270 junit.framework.Assert.assertEquals((("3" + (getDecimalCharacter())) + "14"), text);271 }272 public void testFormatObject() {273 try {274 org.apache.commons.math.util.CompositeFormat cf = new org.apache.commons.math.complex.ComplexFormat();275 java.lang.Object object = new java.lang.Object();276 cf.format(object);277 junit.framework.Assert.fail();278 } catch (java.lang.IllegalArgumentException ex) {279 }280 }281 public void testForgottenImaginaryCharacter() {282 java.text.ParsePosition pos = new java.text.ParsePosition(0);283 junit.framework.Assert.assertNull(new org.apache.commons.math.complex.ComplexFormat().parse("1 + 1", pos));284 junit.framework.Assert.assertEquals(5, pos.getErrorIndex());285 }286}...

Full Screen

Full Screen

Source:Vector3DFormatAbstractTest.java Github

copy

Full Screen

...13 }14 public void testSimpleNoDecimals() {15 org.apache.commons.math.geometry.Vector3D c = new org.apache.commons.math.geometry.Vector3D(1 , 1 , 1);16 java.lang.String expected = "{1; 1; 1}";17 java.lang.String actual = vector3DFormat.format(c);18 junit.framework.Assert.assertEquals(expected, actual);19 }20 public void testSimpleWithDecimals() {21 org.apache.commons.math.geometry.Vector3D c = new org.apache.commons.math.geometry.Vector3D(1.23 , 1.43 , 1.63);22 java.lang.String expected = ((((("{1" + (getDecimalCharacter())) + "23; 1") + (getDecimalCharacter())) + "43; 1") + (getDecimalCharacter())) + "63}";23 java.lang.String actual = vector3DFormat.format(c);24 junit.framework.Assert.assertEquals(expected, actual);25 }26 public void testSimpleWithDecimalsTrunc() {27 org.apache.commons.math.geometry.Vector3D c = new org.apache.commons.math.geometry.Vector3D(1.2323 , 1.4343 , 1.6333);28 java.lang.String expected = ((((("{1" + (getDecimalCharacter())) + "23; 1") + (getDecimalCharacter())) + "43; 1") + (getDecimalCharacter())) + "63}";29 java.lang.String actual = vector3DFormat.format(c);30 junit.framework.Assert.assertEquals(expected, actual);31 }32 public void testNegativeX() {33 org.apache.commons.math.geometry.Vector3D c = new org.apache.commons.math.geometry.Vector3D(-1.2323 , 1.4343 , 1.6333);34 java.lang.String expected = ((((("{-1" + (getDecimalCharacter())) + "23; 1") + (getDecimalCharacter())) + "43; 1") + (getDecimalCharacter())) + "63}";35 java.lang.String actual = vector3DFormat.format(c);36 junit.framework.Assert.assertEquals(expected, actual);37 }38 public void testNegativeY() {39 org.apache.commons.math.geometry.Vector3D c = new org.apache.commons.math.geometry.Vector3D(1.2323 , -1.4343 , 1.6333);40 java.lang.String expected = ((((("{1" + (getDecimalCharacter())) + "23; -1") + (getDecimalCharacter())) + "43; 1") + (getDecimalCharacter())) + "63}";41 java.lang.String actual = vector3DFormat.format(c);42 junit.framework.Assert.assertEquals(expected, actual);43 }44 public void testNegativeZ() {45 org.apache.commons.math.geometry.Vector3D c = new org.apache.commons.math.geometry.Vector3D(1.2323 , 1.4343 , -1.6333);46 java.lang.String expected = ((((("{1" + (getDecimalCharacter())) + "23; 1") + (getDecimalCharacter())) + "43; -1") + (getDecimalCharacter())) + "63}";47 java.lang.String actual = vector3DFormat.format(c);48 junit.framework.Assert.assertEquals(expected, actual);49 }50 public void testNonDefaultSetting() {51 org.apache.commons.math.geometry.Vector3D c = new org.apache.commons.math.geometry.Vector3D(1 , 1 , 1);52 java.lang.String expected = "[1 : 1 : 1]";53 java.lang.String actual = vector3DFormatSquare.format(c);54 junit.framework.Assert.assertEquals(expected, actual);55 }56 public void testStaticFormatVector3D() {57 java.util.Locale defaultLocal = java.util.Locale.getDefault();58 java.util.Locale.setDefault(getLocale());59 org.apache.commons.math.geometry.Vector3D c = new org.apache.commons.math.geometry.Vector3D(232.222 , -342.33 , 432.444);60 java.lang.String expected = ((((("{232" + (getDecimalCharacter())) + "22; -342") + (getDecimalCharacter())) + "33; 432") + (getDecimalCharacter())) + "44}";61 java.lang.String actual = org.apache.commons.math.geometry.Vector3DFormat.formatVector3D(c);62 junit.framework.Assert.assertEquals(expected, actual);63 java.util.Locale.setDefault(defaultLocal);64 }65 public void testNan() {66 org.apache.commons.math.geometry.Vector3D c = org.apache.commons.math.geometry.Vector3D.NaN;67 java.lang.String expected = "{(NaN); (NaN); (NaN)}";68 java.lang.String actual = vector3DFormat.format(c);69 junit.framework.Assert.assertEquals(expected, actual);70 }71 public void testPositiveInfinity() {72 org.apache.commons.math.geometry.Vector3D c = org.apache.commons.math.geometry.Vector3D.POSITIVE_INFINITY;73 java.lang.String expected = "{(Infinity); (Infinity); (Infinity)}";74 java.lang.String actual = vector3DFormat.format(c);75 junit.framework.Assert.assertEquals(expected, actual);76 }77 public void tesNegativeInfinity() {78 org.apache.commons.math.geometry.Vector3D c = org.apache.commons.math.geometry.Vector3D.NEGATIVE_INFINITY;79 java.lang.String expected = "{(-Infinity); (-Infinity); (-Infinity)}";80 java.lang.String actual = vector3DFormat.format(c);81 junit.framework.Assert.assertEquals(expected, actual);82 }83 public void testParseSimpleNoDecimals() {84 java.lang.String source = "{1; 1; 1}";85 org.apache.commons.math.geometry.Vector3D expected = new org.apache.commons.math.geometry.Vector3D(1 , 1 , 1);86 try {87 org.apache.commons.math.geometry.Vector3D actual = ((org.apache.commons.math.geometry.Vector3D)(vector3DFormat.parseObject(source)));88 junit.framework.Assert.assertEquals(expected, actual);89 } catch (java.text.ParseException ex) {90 junit.framework.Assert.fail(ex.getMessage());91 }92 }93 public void testParseIgnoredWhitespace() {94 org.apache.commons.math.geometry.Vector3D expected = new org.apache.commons.math.geometry.Vector3D(1 , 1 , 1);95 java.text.ParsePosition pos1 = new java.text.ParsePosition(0);96 java.lang.String source1 = "{1;1;1}";97 junit.framework.Assert.assertEquals(expected, vector3DFormat.parseObject(source1, pos1));98 junit.framework.Assert.assertEquals(source1.length(), pos1.getIndex());99 java.text.ParsePosition pos2 = new java.text.ParsePosition(0);100 java.lang.String source2 = " { 1 ; 1 ; 1 } ";101 junit.framework.Assert.assertEquals(expected, vector3DFormat.parseObject(source2, pos2));102 junit.framework.Assert.assertEquals(((source2.length()) - 1), pos2.getIndex());103 }104 public void testParseSimpleWithDecimals() {105 java.lang.String source = ((((("{1" + (getDecimalCharacter())) + "23; 1") + (getDecimalCharacter())) + "43; 1") + (getDecimalCharacter())) + "63}";106 org.apache.commons.math.geometry.Vector3D expected = new org.apache.commons.math.geometry.Vector3D(1.23 , 1.43 , 1.63);107 try {108 org.apache.commons.math.geometry.Vector3D actual = ((org.apache.commons.math.geometry.Vector3D)(vector3DFormat.parseObject(source)));109 junit.framework.Assert.assertEquals(expected, actual);110 } catch (java.text.ParseException ex) {111 junit.framework.Assert.fail(ex.getMessage());112 }113 }114 public void testParseSimpleWithDecimalsTrunc() {115 java.lang.String source = ((((("{1" + (getDecimalCharacter())) + "2323; 1") + (getDecimalCharacter())) + "4343; 1") + (getDecimalCharacter())) + "6333}";116 org.apache.commons.math.geometry.Vector3D expected = new org.apache.commons.math.geometry.Vector3D(1.2323 , 1.4343 , 1.6333);117 try {118 org.apache.commons.math.geometry.Vector3D actual = ((org.apache.commons.math.geometry.Vector3D)(vector3DFormat.parseObject(source)));119 junit.framework.Assert.assertEquals(expected, actual);120 } catch (java.text.ParseException ex) {121 junit.framework.Assert.fail(ex.getMessage());122 }123 }124 public void testParseNegativeX() {125 java.lang.String source = ((((("{-1" + (getDecimalCharacter())) + "2323; 1") + (getDecimalCharacter())) + "4343; 1") + (getDecimalCharacter())) + "6333}";126 org.apache.commons.math.geometry.Vector3D expected = new org.apache.commons.math.geometry.Vector3D(-1.2323 , 1.4343 , 1.6333);127 try {128 org.apache.commons.math.geometry.Vector3D actual = ((org.apache.commons.math.geometry.Vector3D)(vector3DFormat.parseObject(source)));129 junit.framework.Assert.assertEquals(expected, actual);130 } catch (java.text.ParseException ex) {131 junit.framework.Assert.fail(ex.getMessage());132 }133 }134 public void testParseNegativeY() {135 java.lang.String source = ((((("{1" + (getDecimalCharacter())) + "2323; -1") + (getDecimalCharacter())) + "4343; 1") + (getDecimalCharacter())) + "6333}";136 org.apache.commons.math.geometry.Vector3D expected = new org.apache.commons.math.geometry.Vector3D(1.2323 , -1.4343 , 1.6333);137 try {138 org.apache.commons.math.geometry.Vector3D actual = ((org.apache.commons.math.geometry.Vector3D)(vector3DFormat.parseObject(source)));139 junit.framework.Assert.assertEquals(expected, actual);140 } catch (java.text.ParseException ex) {141 junit.framework.Assert.fail(ex.getMessage());142 }143 }144 public void testParseNegativeZ() {145 java.lang.String source = ((((("{1" + (getDecimalCharacter())) + "2323; 1") + (getDecimalCharacter())) + "4343; -1") + (getDecimalCharacter())) + "6333}";146 org.apache.commons.math.geometry.Vector3D expected = new org.apache.commons.math.geometry.Vector3D(1.2323 , 1.4343 , -1.6333);147 try {148 org.apache.commons.math.geometry.Vector3D actual = ((org.apache.commons.math.geometry.Vector3D)(vector3DFormat.parseObject(source)));149 junit.framework.Assert.assertEquals(expected, actual);150 } catch (java.text.ParseException ex) {151 junit.framework.Assert.fail(ex.getMessage());152 }153 }154 public void testParseNegativeAll() {155 java.lang.String source = ((((("{-1" + (getDecimalCharacter())) + "2323; -1") + (getDecimalCharacter())) + "4343; -1") + (getDecimalCharacter())) + "6333}";156 org.apache.commons.math.geometry.Vector3D expected = new org.apache.commons.math.geometry.Vector3D(-1.2323 , -1.4343 , -1.6333);157 try {158 org.apache.commons.math.geometry.Vector3D actual = ((org.apache.commons.math.geometry.Vector3D)(vector3DFormat.parseObject(source)));159 junit.framework.Assert.assertEquals(expected, actual);160 } catch (java.text.ParseException ex) {161 junit.framework.Assert.fail(ex.getMessage());162 }163 }164 public void testParseZeroX() {165 java.lang.String source = ((((("{0" + (getDecimalCharacter())) + "0; -1") + (getDecimalCharacter())) + "4343; 1") + (getDecimalCharacter())) + "6333}";166 org.apache.commons.math.geometry.Vector3D expected = new org.apache.commons.math.geometry.Vector3D(0.0 , -1.4343 , 1.6333);167 try {168 org.apache.commons.math.geometry.Vector3D actual = ((org.apache.commons.math.geometry.Vector3D)(vector3DFormat.parseObject(source)));169 junit.framework.Assert.assertEquals(expected, actual);170 } catch (java.text.ParseException ex) {171 junit.framework.Assert.fail(ex.getMessage());172 }173 }174 public void testParseNonDefaultSetting() {175 java.lang.String source = ((((("[1" + (getDecimalCharacter())) + "2323 : 1") + (getDecimalCharacter())) + "4343 : 1") + (getDecimalCharacter())) + "6333]";176 org.apache.commons.math.geometry.Vector3D expected = new org.apache.commons.math.geometry.Vector3D(1.2323 , 1.4343 , 1.6333);177 try {178 org.apache.commons.math.geometry.Vector3D actual = ((org.apache.commons.math.geometry.Vector3D)(vector3DFormatSquare.parseObject(source)));179 junit.framework.Assert.assertEquals(expected, actual);180 } catch (java.text.ParseException ex) {181 junit.framework.Assert.fail(ex.getMessage());182 }183 }184 public void testParseNan() {185 java.lang.String source = "{(NaN); (NaN); (NaN)}";186 try {187 org.apache.commons.math.geometry.Vector3D actual = ((org.apache.commons.math.geometry.Vector3D)(vector3DFormat.parseObject(source)));188 junit.framework.Assert.assertEquals(org.apache.commons.math.geometry.Vector3D.NaN, actual);189 } catch (java.text.ParseException ex) {190 junit.framework.Assert.fail(ex.getMessage());191 }192 }193 public void testParsePositiveInfinity() {194 java.lang.String source = "{(Infinity); (Infinity); (Infinity)}";195 try {196 org.apache.commons.math.geometry.Vector3D actual = ((org.apache.commons.math.geometry.Vector3D)(vector3DFormat.parseObject(source)));197 junit.framework.Assert.assertEquals(org.apache.commons.math.geometry.Vector3D.POSITIVE_INFINITY, actual);198 } catch (java.text.ParseException ex) {199 junit.framework.Assert.fail(ex.getMessage());200 }201 }202 public void testParseNegativeInfinity() {203 java.lang.String source = "{(-Infinity); (-Infinity); (-Infinity)}";204 try {205 org.apache.commons.math.geometry.Vector3D actual = ((org.apache.commons.math.geometry.Vector3D)(vector3DFormat.parseObject(source)));206 junit.framework.Assert.assertEquals(org.apache.commons.math.geometry.Vector3D.NEGATIVE_INFINITY, actual);207 } catch (java.text.ParseException ex) {208 junit.framework.Assert.fail(ex.getMessage());209 }210 }211 public void testConstructorSingleFormat() {212 java.text.NumberFormat nf = java.text.NumberFormat.getInstance();213 org.apache.commons.math.geometry.Vector3DFormat cf = new org.apache.commons.math.geometry.Vector3DFormat(nf);214 junit.framework.Assert.assertNotNull(cf);215 junit.framework.Assert.assertEquals(nf, cf.getFormat());216 }217 public void testFormatObject() {218 try {219 org.apache.commons.math.util.CompositeFormat cf = new org.apache.commons.math.geometry.Vector3DFormat();220 java.lang.Object object = new java.lang.Object();221 cf.format(object);222 junit.framework.Assert.fail();223 } catch (java.lang.IllegalArgumentException ex) {224 }225 }226 public void testForgottenPrefix() {227 java.text.ParsePosition pos = new java.text.ParsePosition(0);228 junit.framework.Assert.assertNull(new org.apache.commons.math.geometry.Vector3DFormat().parse("1; 1; 1}", pos));229 junit.framework.Assert.assertEquals(0, pos.getErrorIndex());230 }231 public void testForgottenSeparator() {232 java.text.ParsePosition pos = new java.text.ParsePosition(0);233 junit.framework.Assert.assertNull(new org.apache.commons.math.geometry.Vector3DFormat().parse("{1; 1 1}", pos));234 junit.framework.Assert.assertEquals(6, pos.getErrorIndex());235 }...

Full Screen

Full Screen

Source:BigFractionFormatTest.java Github

copy

Full Screen

...12 }13 public void testFormat() {14 org.apache.commons.math.fraction.BigFraction c = new org.apache.commons.math.fraction.BigFraction(1 , 2);15 java.lang.String expected = "1 / 2";16 java.lang.String actual = properFormat.format(c);17 junit.framework.Assert.assertEquals(expected, actual);18 actual = improperFormat.format(c);19 junit.framework.Assert.assertEquals(expected, actual);20 }21 public void testFormatNegative() {22 org.apache.commons.math.fraction.BigFraction c = new org.apache.commons.math.fraction.BigFraction(-1 , 2);23 java.lang.String expected = "-1 / 2";24 java.lang.String actual = properFormat.format(c);25 junit.framework.Assert.assertEquals(expected, actual);26 actual = improperFormat.format(c);27 junit.framework.Assert.assertEquals(expected, actual);28 }29 public void testFormatZero() {30 org.apache.commons.math.fraction.BigFraction c = new org.apache.commons.math.fraction.BigFraction(0 , 1);31 java.lang.String expected = "0 / 1";32 java.lang.String actual = properFormat.format(c);33 junit.framework.Assert.assertEquals(expected, actual);34 actual = improperFormat.format(c);35 junit.framework.Assert.assertEquals(expected, actual);36 }37 public void testFormatImproper() {38 org.apache.commons.math.fraction.BigFraction c = new org.apache.commons.math.fraction.BigFraction(5 , 3);39 java.lang.String actual = properFormat.format(c);40 junit.framework.Assert.assertEquals("1 2 / 3", actual);41 actual = improperFormat.format(c);42 junit.framework.Assert.assertEquals("5 / 3", actual);43 }44 public void testFormatImproperNegative() {45 org.apache.commons.math.fraction.BigFraction c = new org.apache.commons.math.fraction.BigFraction(-5 , 3);46 java.lang.String actual = properFormat.format(c);47 junit.framework.Assert.assertEquals("-1 2 / 3", actual);48 actual = improperFormat.format(c);49 junit.framework.Assert.assertEquals("-5 / 3", actual);50 }51 public void testParse() {52 java.lang.String source = "1 / 2";53 try {54 org.apache.commons.math.fraction.BigFraction c = properFormat.parse(source);55 junit.framework.Assert.assertNotNull(c);56 junit.framework.Assert.assertEquals(java.math.BigInteger.ONE, c.getNumerator());57 junit.framework.Assert.assertEquals(java.math.BigInteger.valueOf(2L), c.getDenominator());58 c = improperFormat.parse(source);59 junit.framework.Assert.assertNotNull(c);60 junit.framework.Assert.assertEquals(java.math.BigInteger.ONE, c.getNumerator());61 junit.framework.Assert.assertEquals(java.math.BigInteger.valueOf(2L), c.getDenominator());62 } catch (java.text.ParseException ex) {63 junit.framework.Assert.fail(ex.getMessage());64 }65 }66 public void testParseInteger() {67 java.lang.String source = "10";68 try {69 org.apache.commons.math.fraction.BigFraction c = properFormat.parse(source);70 junit.framework.Assert.assertNotNull(c);71 junit.framework.Assert.assertEquals(java.math.BigInteger.TEN, c.getNumerator());72 junit.framework.Assert.assertEquals(java.math.BigInteger.ONE, c.getDenominator());73 } catch (java.text.ParseException ex) {74 junit.framework.Assert.fail(ex.getMessage());75 }76 try {77 org.apache.commons.math.fraction.BigFraction c = improperFormat.parse(source);78 junit.framework.Assert.assertNotNull(c);79 junit.framework.Assert.assertEquals(java.math.BigInteger.TEN, c.getNumerator());80 junit.framework.Assert.assertEquals(java.math.BigInteger.ONE, c.getDenominator());81 } catch (java.text.ParseException ex) {82 junit.framework.Assert.fail(ex.getMessage());83 }84 }85 public void testParseInvalid() {86 java.lang.String source = "a";87 java.lang.String msg = "should not be able to parse '10 / a'.";88 try {89 properFormat.parse(source);90 junit.framework.Assert.fail(msg);91 } catch (java.text.ParseException ex) {92 }93 try {94 improperFormat.parse(source);95 junit.framework.Assert.fail(msg);96 } catch (java.text.ParseException ex) {97 }98 }99 public void testParseInvalidDenominator() {100 java.lang.String source = "10 / a";101 java.lang.String msg = "should not be able to parse '10 / a'.";102 try {103 properFormat.parse(source);104 junit.framework.Assert.fail(msg);105 } catch (java.text.ParseException ex) {106 }107 try {108 improperFormat.parse(source);109 junit.framework.Assert.fail(msg);110 } catch (java.text.ParseException ex) {111 }112 }113 public void testParseNegative() {114 try {115 java.lang.String source = "-1 / 2";116 org.apache.commons.math.fraction.BigFraction c = properFormat.parse(source);117 junit.framework.Assert.assertNotNull(c);118 junit.framework.Assert.assertEquals(-1, c.getNumeratorAsInt());119 junit.framework.Assert.assertEquals(2, c.getDenominatorAsInt());120 c = improperFormat.parse(source);121 junit.framework.Assert.assertNotNull(c);122 junit.framework.Assert.assertEquals(-1, c.getNumeratorAsInt());123 junit.framework.Assert.assertEquals(2, c.getDenominatorAsInt());124 source = "1 / -2";125 c = properFormat.parse(source);126 junit.framework.Assert.assertNotNull(c);127 junit.framework.Assert.assertEquals(-1, c.getNumeratorAsInt());128 junit.framework.Assert.assertEquals(2, c.getDenominatorAsInt());129 c = improperFormat.parse(source);130 junit.framework.Assert.assertNotNull(c);131 junit.framework.Assert.assertEquals(-1, c.getNumeratorAsInt());132 junit.framework.Assert.assertEquals(2, c.getDenominatorAsInt());133 } catch (java.text.ParseException ex) {134 junit.framework.Assert.fail(ex.getMessage());135 }136 }137 public void testParseProper() {138 java.lang.String source = "1 2 / 3";139 try {140 org.apache.commons.math.fraction.BigFraction c = properFormat.parse(source);141 junit.framework.Assert.assertNotNull(c);142 junit.framework.Assert.assertEquals(5, c.getNumeratorAsInt());143 junit.framework.Assert.assertEquals(3, c.getDenominatorAsInt());144 } catch (java.text.ParseException ex) {145 junit.framework.Assert.fail(ex.getMessage());146 }147 try {148 improperFormat.parse(source);149 junit.framework.Assert.fail("invalid improper fraction.");150 } catch (java.text.ParseException ex) {151 }152 }153 public void testParseProperNegative() {154 java.lang.String source = "-1 2 / 3";155 try {156 org.apache.commons.math.fraction.BigFraction c = properFormat.parse(source);157 junit.framework.Assert.assertNotNull(c);158 junit.framework.Assert.assertEquals(-5, c.getNumeratorAsInt());159 junit.framework.Assert.assertEquals(3, c.getDenominatorAsInt());160 } catch (java.text.ParseException ex) {161 junit.framework.Assert.fail(ex.getMessage());162 }163 try {164 improperFormat.parse(source);165 junit.framework.Assert.fail("invalid improper fraction.");166 } catch (java.text.ParseException ex) {167 }168 }169 public void testParseProperInvalidMinus() {170 java.lang.String source = "2 -2 / 3";171 try {172 properFormat.parse(source);173 junit.framework.Assert.fail("invalid minus in improper fraction.");174 } catch (java.text.ParseException ex) {175 }176 source = "2 2 / -3";177 try {178 properFormat.parse(source);179 junit.framework.Assert.fail("invalid minus in improper fraction.");180 } catch (java.text.ParseException ex) {181 }182 }183 public void testParseBig() throws java.text.ParseException {184 org.apache.commons.math.fraction.BigFraction f1 = improperFormat.parse(("167213075789791382630275400487886041651764456874403" + (" / " + "53225575123090058458126718248444563466137046489291")));185 junit.framework.Assert.assertEquals(java.lang.Math.PI, f1.doubleValue(), 0.0);186 org.apache.commons.math.fraction.BigFraction f2 = properFormat.parse(("3 " + ("7536350420521207255895245742552351253353317406530" + (" / " + "53225575123090058458126718248444563466137046489291"))));187 junit.framework.Assert.assertEquals(java.lang.Math.PI, f2.doubleValue(), 0.0);188 junit.framework.Assert.assertEquals(f1, f2);189 java.math.BigDecimal pi = new java.math.BigDecimal("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068");190 junit.framework.Assert.assertEquals(pi, f1.bigDecimalValue(99, java.math.BigDecimal.ROUND_HALF_EVEN));191 }192 public void testNumeratorFormat() {193 java.text.NumberFormat old = properFormat.getNumeratorFormat();194 java.text.NumberFormat nf = java.text.NumberFormat.getInstance();195 nf.setParseIntegerOnly(true);196 properFormat.setNumeratorFormat(nf);197 junit.framework.Assert.assertEquals(nf, properFormat.getNumeratorFormat());198 properFormat.setNumeratorFormat(old);199 old = improperFormat.getNumeratorFormat();200 nf = java.text.NumberFormat.getInstance();201 nf.setParseIntegerOnly(true);202 improperFormat.setNumeratorFormat(nf);203 junit.framework.Assert.assertEquals(nf, improperFormat.getNumeratorFormat());204 improperFormat.setNumeratorFormat(old);205 }206 public void testDenominatorFormat() {207 java.text.NumberFormat old = properFormat.getDenominatorFormat();208 java.text.NumberFormat nf = java.text.NumberFormat.getInstance();209 nf.setParseIntegerOnly(true);210 properFormat.setDenominatorFormat(nf);211 junit.framework.Assert.assertEquals(nf, properFormat.getDenominatorFormat());212 properFormat.setDenominatorFormat(old);213 old = improperFormat.getDenominatorFormat();214 nf = java.text.NumberFormat.getInstance();215 nf.setParseIntegerOnly(true);216 improperFormat.setDenominatorFormat(nf);217 junit.framework.Assert.assertEquals(nf, improperFormat.getDenominatorFormat());218 improperFormat.setDenominatorFormat(old);219 }220 public void testWholeFormat() {221 org.apache.commons.math.fraction.ProperBigFractionFormat format = ((org.apache.commons.math.fraction.ProperBigFractionFormat)(properFormat));222 java.text.NumberFormat old = format.getWholeFormat();223 java.text.NumberFormat nf = java.text.NumberFormat.getInstance();224 nf.setParseIntegerOnly(true);225 format.setWholeFormat(nf);226 junit.framework.Assert.assertEquals(nf, format.getWholeFormat());227 format.setWholeFormat(old);228 }229 public void testLongFormat() {230 junit.framework.Assert.assertEquals("10 / 1", improperFormat.format(10L));231 }232 public void testDoubleFormat() {233 junit.framework.Assert.assertEquals("1 / 16", improperFormat.format(0.0625));234 }235}...

Full Screen

Full Screen

Source:FractionFormatTest.java Github

copy

Full Screen

...12 }13 public void testFormat() {14 org.apache.commons.math.fraction.Fraction c = new org.apache.commons.math.fraction.Fraction(1 , 2);15 java.lang.String expected = "1 / 2";16 java.lang.String actual = properFormat.format(c);17 junit.framework.Assert.assertEquals(expected, actual);18 actual = improperFormat.format(c);19 junit.framework.Assert.assertEquals(expected, actual);20 }21 public void testFormatNegative() {22 org.apache.commons.math.fraction.Fraction c = new org.apache.commons.math.fraction.Fraction(-1 , 2);23 java.lang.String expected = "-1 / 2";24 java.lang.String actual = properFormat.format(c);25 junit.framework.Assert.assertEquals(expected, actual);26 actual = improperFormat.format(c);27 junit.framework.Assert.assertEquals(expected, actual);28 }29 public void testFormatZero() {30 org.apache.commons.math.fraction.Fraction c = new org.apache.commons.math.fraction.Fraction(0 , 1);31 java.lang.String expected = "0 / 1";32 java.lang.String actual = properFormat.format(c);33 junit.framework.Assert.assertEquals(expected, actual);34 actual = improperFormat.format(c);35 junit.framework.Assert.assertEquals(expected, actual);36 }37 public void testFormatImproper() {38 org.apache.commons.math.fraction.Fraction c = new org.apache.commons.math.fraction.Fraction(5 , 3);39 java.lang.String actual = properFormat.format(c);40 junit.framework.Assert.assertEquals("1 2 / 3", actual);41 actual = improperFormat.format(c);42 junit.framework.Assert.assertEquals("5 / 3", actual);43 }44 public void testFormatImproperNegative() {45 org.apache.commons.math.fraction.Fraction c = new org.apache.commons.math.fraction.Fraction(-5 , 3);46 java.lang.String actual = properFormat.format(c);47 junit.framework.Assert.assertEquals("-1 2 / 3", actual);48 actual = improperFormat.format(c);49 junit.framework.Assert.assertEquals("-5 / 3", actual);50 }51 public void testParse() {52 java.lang.String source = "1 / 2";53 try {54 org.apache.commons.math.fraction.Fraction c = properFormat.parse(source);55 junit.framework.Assert.assertNotNull(c);56 junit.framework.Assert.assertEquals(1, c.getNumerator());57 junit.framework.Assert.assertEquals(2, c.getDenominator());58 c = improperFormat.parse(source);59 junit.framework.Assert.assertNotNull(c);60 junit.framework.Assert.assertEquals(1, c.getNumerator());61 junit.framework.Assert.assertEquals(2, c.getDenominator());62 } catch (java.text.ParseException ex) {63 junit.framework.Assert.fail(ex.getMessage());64 }65 }66 public void testParseInteger() {67 java.lang.String source = "10";68 try {69 org.apache.commons.math.fraction.Fraction c = properFormat.parse(source);70 junit.framework.Assert.assertNotNull(c);71 junit.framework.Assert.assertEquals(10, c.getNumerator());72 junit.framework.Assert.assertEquals(1, c.getDenominator());73 } catch (java.text.ParseException ex) {74 junit.framework.Assert.fail(ex.getMessage());75 }76 try {77 org.apache.commons.math.fraction.Fraction c = improperFormat.parse(source);78 junit.framework.Assert.assertNotNull(c);79 junit.framework.Assert.assertEquals(10, c.getNumerator());80 junit.framework.Assert.assertEquals(1, c.getDenominator());81 } catch (java.text.ParseException ex) {82 junit.framework.Assert.fail(ex.getMessage());83 }84 }85 public void testParseInvalid() {86 java.lang.String source = "a";87 java.lang.String msg = "should not be able to parse '10 / a'.";88 try {89 properFormat.parse(source);90 junit.framework.Assert.fail(msg);91 } catch (java.text.ParseException ex) {92 }93 try {94 improperFormat.parse(source);95 junit.framework.Assert.fail(msg);96 } catch (java.text.ParseException ex) {97 }98 }99 public void testParseInvalidDenominator() {100 java.lang.String source = "10 / a";101 java.lang.String msg = "should not be able to parse '10 / a'.";102 try {103 properFormat.parse(source);104 junit.framework.Assert.fail(msg);105 } catch (java.text.ParseException ex) {106 }107 try {108 improperFormat.parse(source);109 junit.framework.Assert.fail(msg);110 } catch (java.text.ParseException ex) {111 }112 }113 public void testParseNegative() {114 try {115 java.lang.String source = "-1 / 2";116 org.apache.commons.math.fraction.Fraction c = properFormat.parse(source);117 junit.framework.Assert.assertNotNull(c);118 junit.framework.Assert.assertEquals(-1, c.getNumerator());119 junit.framework.Assert.assertEquals(2, c.getDenominator());120 c = improperFormat.parse(source);121 junit.framework.Assert.assertNotNull(c);122 junit.framework.Assert.assertEquals(-1, c.getNumerator());123 junit.framework.Assert.assertEquals(2, c.getDenominator());124 source = "1 / -2";125 c = properFormat.parse(source);126 junit.framework.Assert.assertNotNull(c);127 junit.framework.Assert.assertEquals(-1, c.getNumerator());128 junit.framework.Assert.assertEquals(2, c.getDenominator());129 c = improperFormat.parse(source);130 junit.framework.Assert.assertNotNull(c);131 junit.framework.Assert.assertEquals(-1, c.getNumerator());132 junit.framework.Assert.assertEquals(2, c.getDenominator());133 } catch (java.text.ParseException ex) {134 junit.framework.Assert.fail(ex.getMessage());135 }136 }137 public void testParseProper() {138 java.lang.String source = "1 2 / 3";139 try {140 org.apache.commons.math.fraction.Fraction c = properFormat.parse(source);141 junit.framework.Assert.assertNotNull(c);142 junit.framework.Assert.assertEquals(5, c.getNumerator());143 junit.framework.Assert.assertEquals(3, c.getDenominator());144 } catch (java.text.ParseException ex) {145 junit.framework.Assert.fail(ex.getMessage());146 }147 try {148 improperFormat.parse(source);149 junit.framework.Assert.fail("invalid improper fraction.");150 } catch (java.text.ParseException ex) {151 }152 }153 public void testParseProperNegative() {154 java.lang.String source = "-1 2 / 3";155 try {156 org.apache.commons.math.fraction.Fraction c = properFormat.parse(source);157 junit.framework.Assert.assertNotNull(c);158 junit.framework.Assert.assertEquals(-5, c.getNumerator());159 junit.framework.Assert.assertEquals(3, c.getDenominator());160 } catch (java.text.ParseException ex) {161 junit.framework.Assert.fail(ex.getMessage());162 }163 try {164 improperFormat.parse(source);165 junit.framework.Assert.fail("invalid improper fraction.");166 } catch (java.text.ParseException ex) {167 }168 }169 public void testParseProperInvalidMinus() {170 java.lang.String source = "2 -2 / 3";171 try {172 properFormat.parse(source);173 junit.framework.Assert.fail("invalid minus in improper fraction.");174 } catch (java.text.ParseException ex) {175 }176 source = "2 2 / -3";177 try {178 properFormat.parse(source);179 junit.framework.Assert.fail("invalid minus in improper fraction.");180 } catch (java.text.ParseException ex) {181 }182 }183 public void testNumeratorFormat() {184 java.text.NumberFormat old = properFormat.getNumeratorFormat();185 java.text.NumberFormat nf = java.text.NumberFormat.getInstance();186 nf.setParseIntegerOnly(true);187 properFormat.setNumeratorFormat(nf);188 junit.framework.Assert.assertEquals(nf, properFormat.getNumeratorFormat());189 properFormat.setNumeratorFormat(old);190 old = improperFormat.getNumeratorFormat();191 nf = java.text.NumberFormat.getInstance();192 nf.setParseIntegerOnly(true);193 improperFormat.setNumeratorFormat(nf);194 junit.framework.Assert.assertEquals(nf, improperFormat.getNumeratorFormat());195 improperFormat.setNumeratorFormat(old);196 }197 public void testDenominatorFormat() {198 java.text.NumberFormat old = properFormat.getDenominatorFormat();199 java.text.NumberFormat nf = java.text.NumberFormat.getInstance();200 nf.setParseIntegerOnly(true);201 properFormat.setDenominatorFormat(nf);202 junit.framework.Assert.assertEquals(nf, properFormat.getDenominatorFormat());203 properFormat.setDenominatorFormat(old);204 old = improperFormat.getDenominatorFormat();205 nf = java.text.NumberFormat.getInstance();206 nf.setParseIntegerOnly(true);207 improperFormat.setDenominatorFormat(nf);208 junit.framework.Assert.assertEquals(nf, improperFormat.getDenominatorFormat());209 improperFormat.setDenominatorFormat(old);210 }211 public void testWholeFormat() {212 org.apache.commons.math.fraction.ProperFractionFormat format = ((org.apache.commons.math.fraction.ProperFractionFormat)(properFormat));213 java.text.NumberFormat old = format.getWholeFormat();214 java.text.NumberFormat nf = java.text.NumberFormat.getInstance();215 nf.setParseIntegerOnly(true);216 format.setWholeFormat(nf);217 junit.framework.Assert.assertEquals(nf, format.getWholeFormat());218 format.setWholeFormat(old);219 }220 public void testLongFormat() {221 junit.framework.Assert.assertEquals("10 / 1", improperFormat.format(10L));222 }223 public void testDoubleFormat() {224 junit.framework.Assert.assertEquals("355 / 113", improperFormat.format(java.lang.Math.PI));225 }226}...

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1[mark]: # (end:code)2[mark]: # (start:imports)3[imports]: # (end:imports)4[mark]: # (start:code)5[code]: # (end:code)6[mark]: # (start:imports)7[imports]: # (end:imports)8[mark]: # (start:code)9[code]: # (end:code)10[mark]: # (start:imports)11[imports]: # (end:imports)12[mark]: # (start:code)13[code]: # (end:code)14[mark]: # (start:imports)15[imports]: # (end:imports)16[mark]: # (start:code)17[code]: # (end:code)18[mark]: # (start:imports)19[imports]: # (end:imports)20[mark]: # (start:code)21[code]: # (end:code)22[mark]: # (start:imports)23[imports]: # (end:imports)24[mark]: # (start:code)25[code]: # (end:code)26[mark]: # (start:imports)27[imports]: # (end:imports)28[mark]: # (start:code)29[code]: # (end:code)30[mark]: # (start:imports)31[imports]: # (end:imports)

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1import static junit.framework.Assert.format;2import static junit.framework.Assert.assertEquals;3import static junit.framework.Assert.assertTrue;4import static junit.framework.Assert.assertFalse;5import static junit.framework.Assert.assertNotNull;6import static junit.framework.Assert.assertNull;7import static junit.framework.Assert.assertSame;8import static junit.framework.Assert.assertNotSame;9import static junit.framework.Assert.fail;10import static org.hamcrest.MatcherAssert.assertThat;11import static org.hamcrest.Matchers.is;12import static org.hamcrest.Matchers.not;13import static org.hamcrest.Matchers.sameInstance;14import static org.hamcrest.Matchers.notSameInstance;15import static org.hamcrest.Matchers.instanceOf;16import static org.hamcrest.Matchers.notInstanceOf;17import static org.hamcrest.Matchers.equalTo;18import static org.hamcrest.Matchers.notEqualTo;19import static org.hamcrest.Matchers.nullValue;20import static org.hamcrest.Matchers.notNullValue;21import static org.hamcrest.Matchers.hasItem;22import static org.hamcrest.Matchers.notHasItem;23import static org.hamcrest.Matchers.hasItems;24import static org.hamcrest.Matchers.notHasItems;25import static org

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1import static org.junit.Assert.*;2import org.junit.Test;3public class JunitTest {4 String message = "Robert"; 5 MessageUtil messageUtil = new MessageUtil(message);6 public void testPrintMessage() { 7 assertEquals(message, messageUtil.printMessage());8 }9}

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1import junit.framework.Assert;2public class TestFormat {3 public static void main(String[] args) {4 String result = Assert.format("This is %s", "test");5 System.out.println(result);6 }7}8Assert.assertEquals() method9public static void assertEquals(String message, Object expected, Object actual)10package com.journaldev.junit;11import org.junit.Assert;12import org.junit.Test;13public class TestFormat {14 public void testFormat() {15 String result = Assert.format("This is %s", "test");16 Assert.assertEquals("This is test", result);17 }18}19package com.journaldev.junit;20import org.junit.Assert;21import org.junit.Test;22public class TestFormat {23 public void testFormat() {24 String result = Assert.format("This is %s", "test");25 Assert.assertEquals("This is test", result);26 }27}28package com.journaldev.junit;29import org.junit.Assert;30import org.junit.Test;31public class TestFormat {32 public void testFormat() {33 String result = Assert.format("This is %s", "test");34 Assert.assertEquals("This is test", result);35 }36}37package com.journaldev.junit;38import org.junit.Assert;39import org.junit.Test;40public class TestFormat {41 public void testFormat() {42 String result = Assert.format("This is %s", "test");43 Assert.assertEquals("This is test", result);44 }45}46package com.journaldev.junit;47import org.junit.Assert;48import org.junit.Test;49public class TestFormat {50 public void testFormat() {51 String result = Assert.format("This is %s", "test");52 Assert.assertEquals("This is test", result);53 }54}

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1assertThat("String is not empty", str, is(not(emptyString())));2assertThat("String is not blank", str, is(not(blankOrNullString())));3assertThat("String is not empty", str, is(not(emptyString())));assertThat("String is not blank", str, is(not(blankOrNullString())));4assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString())));5assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString())));6assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString())));7assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString())));8assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString())));9assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString())));10assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString())));11assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString())));12assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString())));13assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString())));14assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString())));15assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString())));16assertThat("String is not empty", str, is(not(emptyString()))); assertThat("String is not blank", str, is(not(blankOrNullString()))

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1package com.javacodegeeks.junit;2import junit.framework.Assert;3import org.junit.Test;4public class JUnit4Test {5public void testAssertEquals() {6String val1 = "Junit";7String val2 = "Junit";8Assert.assertEquals("failure - strings are not equal", val1, val2);9}10}11at junit.framework.Assert.fail(Assert.java:47)12at junit.framework.Assert.failNotEquals(Assert.java:282)13at junit.framework.Assert.assertEquals(Assert.java:67)14at junit.framework.Assert.assertEquals(Assert.java:74)15at com.javacodegeeks.junit.JUnit4Test.testAssertEquals(JUnit4Test.java:11)16at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)17at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)18at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)19at java.lang.reflect.Method.invoke(Method.java:597)20at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)21at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:86)22at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:49)23at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:54)24at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:47)25at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:39)26at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:64)27at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:45)28at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:39)29at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:33)30at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:45)31at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:37)32at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(J

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1import junit.framework.Assert;2public class TestAssert {3 public static void main(String[] args) {4 Assert.assertEquals("test message", 1, 2);5 }6}7at junit.framework.Assert.fail(Assert.java:47)8at junit.framework.Assert.failNotEquals(Assert.java:282)9at junit.framework.Assert.assertEquals(Assert.java:67)10at junit.framework.Assert.assertEquals(Assert.java:234)11at junit.framework.Assert.assertEquals(Assert.java:241)12at TestAssert.main(TestAssert.java:8)13at junit.framework.Assert.fail(Assert.java:47)14at junit.framework.Assert.failNotEquals(Assert.java:282)15at junit.framework.Assert.assertEquals(Assert.java:67)16at junit.framework.Assert.assertEquals(Assert.java:234)17at junit.framework.Assert.assertEquals(Assert.java:241)18at TestAssert.main(TestAssert.java:8)19at junit.framework.Assert.fail(Assert.java:47)20at junit.framework.Assert.failNotEquals(Assert.java:282)21at junit.framework.Assert.assertEquals(Assert.java:67)22at junit.framework.Assert.assertEquals(Assert.java:234)23at junit.framework.Assert.assertEquals(Assert.java:241)24at TestAssert.main(TestAssert.java:8)25at junit.framework.Assert.fail(Assert.java:47)26at junit.framework.Assert.failNotEquals(Assert.java:282)27at junit.framework.Assert.assertEquals(Assert.java:67)28at junit.framework.Assert.assertEquals(Assert.java:234)29at junit.framework.Assert.assertEquals(Assert.java:241)30at TestAssert.main(TestAssert.java:8)

Full Screen

Full Screen

JUnit Tutorial:

LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.

JUnit Tutorial Chapters:

Here are the detailed JUnit testing chapters to help you get started:

  • Importance of Unit testing - Learn why Unit testing is essential during the development phase to identify bugs and errors.
  • Top Java Unit testing frameworks - Here are the upcoming JUnit automation testing frameworks that you can use in 2023 to boost your unit testing.
  • What is the JUnit framework
  • Why is JUnit testing important - Learn the importance and numerous benefits of using the JUnit testing framework.
  • Features of JUnit - Learn about the numerous features of JUnit and why developers prefer it.
  • JUnit 5 vs. JUnit 4: Differences - Here is a complete comparison between JUnit 5 and JUnit 4 testing frameworks.
  • Setting up the JUnit environment - Learn how to set up your JUnit testing environment.
  • Getting started with JUnit testing - After successfully setting up your JUnit environment, this chapter will help you get started with JUnit testing in no time.
  • Parallel testing with JUnit - Parallel Testing can be used to reduce test execution time and improve test efficiency. Learn how to perform parallel testing with JUnit.
  • Annotations in JUnit - When writing automation scripts with JUnit, we can use JUnit annotations to specify the type of methods in our test code. This helps us identify those methods when we run JUnit tests using Selenium WebDriver. Learn in detail what annotations are in JUnit.
  • Assertions in JUnit - Assertions are used to validate or test that the result of an action/functionality is the same as expected. Learn in detail what assertions are and how to use them while performing JUnit testing.
  • Parameterization in JUnit - Parameterized Test enables you to run the same automated test scripts with different variables. By collecting data on each method's test parameters, you can minimize time spent on writing tests. Learn how to use parameterization in JUnit.
  • Nested Tests In JUnit 5 - A nested class is a non-static class contained within another class in a hierarchical structure. It can share the state and setup of the outer class. Learn about nested annotations in JUnit 5 with examples.
  • Best practices for JUnit testing - Learn about the best practices, such as always testing key methods and classes, integrating JUnit tests with your build, and more to get the best possible results.
  • Advanced Use Cases for JUnit testing - Take a deep dive into the advanced use cases, such as how to run JUnit tests in Jupiter, how to use JUnit 5 Mockito for Unit testing, and more for JUnit testing.

JUnit Certification:

You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.

Run junit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful