YuleQ { public static double distance(int[] v1, int[] v2){ Asserts.assertEqualLength(v1, v2); Asserts.assertIsBinary(v1); Asserts.assertIsBinary(v2); Asserts.assertHasAllZeros(v1); Asserts.assertHasAllZeros(v2); int[] matches = CommonStats.processTwoBinaryVectors(v1, v2); return (1-((double)((matches[0]*matches[3])-(matches[1]*matches[2]))/(double)((matches[0]*matches[3])+(matches[1]*matches[2]))))/2; }  static double distance(int[] v1, int[] v2);  }
@Test public void test1(){ int[] v1 = new int[]{1,0,1}; int[] v2 = new int[]{1,1,0}; Asserts.assertEqualLength(v1, v2); double res = YuleQ.distance(v1, v2); Asserts.assertEquals(res, 1); }
@Test public void test2(){ int[] v1 = new int[]{1,1,0,0}; int[] v2 = new int[]{0,1,0,1}; Asserts.assertEqualLength(v1, v2); double res = YuleQ.distance(v1, v2); Asserts.assertEquals(res, 0.5); }
@Test public void test3(){ int[] v1 = new int[]{1,0,0,1,1}; int[] v2 = new int[]{1,1,0,1,0}; Asserts.assertEqualLength(v1, v2); double res = YuleQ.distance(v1, v2); Asserts.assertEquals(res, 0.3333333); }
@Test public void test4(){ int[] v1 = new int[]{1,0,1,1,0,1}; int[] v2 = new int[]{1,1,0,1,1,0}; Asserts.assertEqualLength(v1, v2); double res = YuleQ.distance(v1, v2); Asserts.assertEquals(res, 1); }
@Test public void test5(){ int[] v1 = new int[]{1,0,1,1,0,1,1}; int[] v2 = new int[]{1,1,0,1,1,0,1}; Asserts.assertEqualLength(v1, v2); double res = YuleQ.distance(v1, v2); Asserts.assertEquals(res, 1); }
@Test public void test6(){ int[] v1 = new int[]{1,0,1,1,0,1,1,0}; int[] v2 = new int[]{1,1,0,1,1,0,0,1}; Asserts.assertEqualLength(v1, v2); double res = YuleQ.distance(v1, v2); Asserts.assertEquals(res, 1); }
@Test public void test7(){ int[] v1 = new int[]{1,0,1,1,0,1,1,0,0}; int[] v2 = new int[]{1,1,0,1,1,0,0,1,0}; Asserts.assertEqualLength(v1, v2); double res = YuleQ.distance(v1, v2); Asserts.assertEquals(res, 0.818181818); }
@Test public void test8(){ int[] v1 = new int[]{1,0,1,1,0,1,1,0,1,0}; int[] v2 = new int[]{1,1,0,1,1,0,0,1,1,0}; Asserts.assertEqualLength(v1, v2); double res = YuleQ.distance(v1, v2); Asserts.assertEquals(res, 0.75); }