Changeset 16252 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2020-04-11T08:54:12+02:00 (5 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/tools/ColorHelperTest.java
r9669 r16252 15 15 16 16 /** 17 * Unit test of method {@link ColorHelper#html2color}. 18 */ 19 @Test 20 public void testHtml2color() { 21 assertNull(ColorHelper.html2color("")); 22 assertNull(ColorHelper.html2color("xyz")); 23 assertEquals(Color.CYAN, ColorHelper.html2color("0ff")); 24 assertEquals(Color.CYAN, ColorHelper.html2color("#0ff")); 25 assertEquals(Color.CYAN, ColorHelper.html2color("00ffff")); 26 assertEquals(Color.CYAN, ColorHelper.html2color("#00ffff")); 27 assertEquals(Color.CYAN, ColorHelper.html2color("#00FFFF")); 28 assertEquals(new Color(0x12345678, true), ColorHelper.html2color("#34567812")); 29 } 30 31 /** 32 * Unit test of method {@link ColorHelper#color2html}. 33 */ 34 @Test 35 public void testColor2html() { 36 assertNull(ColorHelper.color2html(null)); 37 assertEquals("#FF0000", ColorHelper.color2html(Color.RED)); 38 assertEquals("#00FFFF", ColorHelper.color2html(Color.CYAN)); 39 assertEquals("#34567812", ColorHelper.color2html(new Color(0x12345678, true))); 40 assertEquals("#34567812", ColorHelper.color2html(new Color(0x12345678, true), true)); 41 assertEquals("#345678", ColorHelper.color2html(new Color(0x12345678, true), false)); 42 } 43 44 /** 17 45 * Unit test of method {@link ColorHelper#getForegroundColor}. 18 46 */ … … 26 54 assertEquals(Color.BLACK, ColorHelper.getForegroundColor(Color.WHITE)); 27 55 } 56 57 /** 58 * Test of {@link ColorHelper#float2int} 59 */ 60 @Test 61 public void testColorFloat2int() { 62 assertNull(ColorHelper.float2int(null)); 63 assertEquals(255, (int) ColorHelper.float2int(-1.0f)); 64 assertEquals(0, (int) ColorHelper.float2int(-0.0f)); 65 assertEquals(0, (int) ColorHelper.float2int(0.0f)); 66 assertEquals(64, (int) ColorHelper.float2int(0.25f)); 67 assertEquals(128, (int) ColorHelper.float2int(0.5f)); 68 assertEquals(255, (int) ColorHelper.float2int(1.0f)); 69 assertEquals(255, (int) ColorHelper.float2int(2.0f)); 70 } 71 72 /** 73 * Test of {@link ColorHelper#int2float} 74 */ 75 @Test 76 public void testColorInt2float() { 77 assertNull(ColorHelper.int2float(null)); 78 assertEquals(1.0f, ColorHelper.int2float(-1), 1e-3); 79 assertEquals(0.0f, ColorHelper.int2float(0), 1e-3); 80 assertEquals(0.25f, ColorHelper.int2float(64), 1e-3); 81 assertEquals(0.502f, ColorHelper.int2float(128), 1e-3); 82 assertEquals(0.753f, ColorHelper.int2float(192), 1e-3); 83 assertEquals(1.0f, ColorHelper.int2float(255), 1e-3); 84 assertEquals(1.0f, ColorHelper.int2float(1024), 1e-3); 85 } 86 87 /** 88 * Test of {@link ColorHelper#alphaMultiply} 89 */ 90 @Test 91 public void testAlphaMultiply() { 92 final Color color = new Color(0x12345678, true); 93 assertEquals(new Color(0x12345678, true), ColorHelper.alphaMultiply(color, 1f)); 94 assertEquals(new Color(0x24345678, true), ColorHelper.alphaMultiply(color, 2f)); 95 } 96 97 /** 98 * Test of {@link ColorHelper#complement} 99 */ 100 @Test 101 public void testComplement() { 102 assertEquals(Color.cyan, ColorHelper.complement(Color.red)); 103 assertEquals(Color.red, ColorHelper.complement(Color.cyan)); 104 assertEquals(Color.magenta, ColorHelper.complement(Color.green)); 105 assertEquals(Color.green, ColorHelper.complement(Color.magenta)); 106 assertEquals(Color.yellow, ColorHelper.complement(Color.blue)); 107 assertEquals(Color.blue, ColorHelper.complement(Color.yellow)); 108 } 28 109 } -
trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
r16182 r16252 8 8 import static org.junit.Assert.assertTrue; 9 9 10 import java.awt.Color;11 10 import java.io.File; 12 11 import java.io.IOException; … … 415 414 416 415 /** 417 * Test of {@link Utils#toString}418 */419 @Test420 public void testToString() {421 assertEquals("null", Utils.toString(null));422 assertEquals("#ff0000", Utils.toString(Color.red));423 assertEquals("#345678(alpha=18)", Utils.toString(new Color(0x12345678, true)));424 }425 426 /**427 * Test of {@link Utils#colorFloat2int}428 */429 @Test430 public void testColorFloat2int() {431 assertNull(Utils.colorFloat2int(null));432 assertEquals(255, (int) Utils.colorFloat2int(-1.0f));433 assertEquals(0, (int) Utils.colorFloat2int(-0.0f));434 assertEquals(0, (int) Utils.colorFloat2int(0.0f));435 assertEquals(64, (int) Utils.colorFloat2int(0.25f));436 assertEquals(128, (int) Utils.colorFloat2int(0.5f));437 assertEquals(255, (int) Utils.colorFloat2int(1.0f));438 assertEquals(255, (int) Utils.colorFloat2int(2.0f));439 }440 441 /**442 * Test of {@link Utils#colorInt2float}443 */444 @Test445 public void testColorInt2float() {446 assertNull(Utils.colorInt2float(null));447 assertEquals(1.0f, Utils.colorInt2float(-1), 1e-3);448 assertEquals(0.0f, Utils.colorInt2float(0), 1e-3);449 assertEquals(0.25f, Utils.colorInt2float(64), 1e-3);450 assertEquals(0.502f, Utils.colorInt2float(128), 1e-3);451 assertEquals(0.753f, Utils.colorInt2float(192), 1e-3);452 assertEquals(1.0f, Utils.colorInt2float(255), 1e-3);453 assertEquals(1.0f, Utils.colorInt2float(1024), 1e-3);454 }455 456 /**457 * Test of {@link Utils#alphaMultiply}458 */459 @Test460 public void testAlphaMultiply() {461 final Color color = new Color(0x12345678, true);462 assertEquals(new Color(0x12345678, true), Utils.alphaMultiply(color, 1f));463 assertEquals(new Color(0x24345678, true), Utils.alphaMultiply(color, 2f));464 }465 466 /**467 * Test of {@link Utils#complement}468 */469 @Test470 public void testComplement() {471 assertEquals(Color.cyan, Utils.complement(Color.red));472 assertEquals(Color.red, Utils.complement(Color.cyan));473 assertEquals(Color.magenta, Utils.complement(Color.green));474 assertEquals(Color.green, Utils.complement(Color.magenta));475 assertEquals(Color.yellow, Utils.complement(Color.blue));476 assertEquals(Color.blue, Utils.complement(Color.yellow));477 }478 479 /**480 416 * Test of {@link Utils#getMatches} 481 417 */
Note:
See TracChangeset
for help on using the changeset viewer.