You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ValuesTest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* *******************************************************************
  2. * Copyright (c) 2003 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Wes Isberg initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.testing.util.options;
  13. import junit.framework.TestCase;
  14. /**
  15. */
  16. public class ValuesTest extends TestCase {
  17. public ValuesTest(String s) {
  18. super(s);
  19. }
  20. public void testInvert() {
  21. checkInvert(new int[0], 0, new int[0]); // no input or missed => none found
  22. checkInvert(new int[0], 1, new int[] {0}); // no missed, input 1 => 1 found
  23. checkInvert(new int[] {0}, 1, new int[] {}); // 1 (all) missed, input 1 => none found
  24. checkInvert(new int[] {}, 1, new int[] {0}); // 0 (none) missed, input 1 => 1 found
  25. checkInvert(new int[] {1,2}, 3, new int[] {0}); // 2 missed, input 3 => 1 (first) found
  26. checkInvert(new int[] {0,2}, 3, new int[] {1}); // 2 missed, input 3 => 1 (middle) found
  27. checkInvert(new int[] {0,1}, 3, new int[] {2}); // 2 missed, input 3 => 1 (last) found
  28. checkInvert(new int[] {1,3}, 4, new int[] {0,2}); // 2 missed, input 4 => 2 found
  29. checkInvert(new int[] {5,6,7}, 8, new int[] {0,1,2,3,4}); // starting run
  30. checkInvert(new int[] {0,1,2,3,4}, 8, new int[] {5,6,7}); // ending run
  31. checkInvert(new int[] {0,5,6,7}, 8, new int[] {1,2,3,4}); // middle run
  32. checkInvert(new int[] {0,5,6,9},10, new int[] {1,2,3,4,7,8}); // two middle run
  33. checkInvert(new int[] {1,2,5,6,9},10, new int[] {0,3,4,7,8}); // start, 2 middle run
  34. checkInvert(new int[] {0,1,2,5,6},10, new int[] {3,4,7,8,9}); // middle, end run
  35. }
  36. void checkInvert(int[] missed, int length, int[] expected) {
  37. int[] actual = Values.invert(missed, length);
  38. assertTrue(null != actual);
  39. assertTrue(actual.length == expected.length);
  40. for (int i = 0; i < actual.length; i++) {
  41. if (expected[i] != actual[i]) {
  42. assertTrue("failed at " + i + render(expected, actual), false);
  43. }
  44. }
  45. }
  46. static String render(int[] expected, int[] actual) {
  47. StringBuffer sb = new StringBuffer();
  48. sb.append(" expected ");
  49. render(expected, sb);
  50. sb.append(" actual ");
  51. render(actual, sb);
  52. return sb.toString();
  53. }
  54. static void render(int[] ra, StringBuffer sb) {
  55. sb.append("[");
  56. for (int i = 0; i < ra.length; i++) {
  57. if (i > 0) {
  58. sb.append(", ");
  59. }
  60. sb.append("" + ra[i]);
  61. }
  62. sb.append("]");
  63. }
  64. }