@Test
    public void testWeight() {
        assertMetrics("weight:1",     "a","a");
        assertMetrics("weight:0",     "y","a");
        assertMetrics("weight:0.3333","a a a","a");
        assertMetrics("weight:1",     "a","a a a");
        assertMetrics("weight:1",     "a b c","a b c");
        assertMetrics("weight:1",     "a b c","x x a b x a x c x x a b x c c x");

        assertMetrics("weight:0.3333","a b c","a");
        assertMetrics("weight:0.6667","a b c","a b");

        assertMetrics("weight:1",   "a b c!200","a b c");     // Best
        assertMetrics("weight:0.75","a b c!200","b c");    // Middle
        assertMetrics("weight:0.5", "a b c!200","a b");     // Worst

        assertMetrics("weight:1","a!300 b c!200","a b c"); // Best too

        assertMetrics("weight:1",  "a b c!50","a b c");   // Best
        assertMetrics("weight:0.6","a b c!50","b c");   // Worse
        assertMetrics("weight:0.4","a b c!50","b");     // Worse
        assertMetrics("weight:0.2","a b c!50","c");     // Worst
        assertMetrics("weight:0.8","a b c!50","a b");   // Middle

        assertMetrics("weight:1",  "a b c!0","a b c");  // Best
        assertMetrics("weight:0.5","a b c!0","b c");  // Worst
        assertMetrics("weight:1",  "a b c!0","a b");    // As good as best
        assertMetrics("weight:0",  "a b c!0","c");      // No contribution

        assertMetrics("weight:0","a!0 b!0","a b");
        assertMetrics("weight:0","a!0 b!0","");

        // The query also has other terms having a total weight of 300
        // so we add a weight parameter which is the sum of the weights of this query terms + 300
        assertMetrics("weight:0.25",  "a","a",400);
        assertMetrics("weight:0",     "y","a",400);
        assertMetrics("weight:0.1667","a a a","a",600);
        assertMetrics("weight:0.25",  "a","a a a",400);
        assertMetrics("weight:0.5",   "a b c","a b c",600);
        assertMetrics("weight:0.5",   "a b c","x x a b x a x c x x a b x c c x",600);

        assertMetrics("weight:0.1667","a b c","a",600);
        assertMetrics("weight:0.3333","a b c","a b",600);

        assertMetrics("weight:0.5714","a b c!200","a b c",700); // Best
        assertMetrics("weight:0.4286","a b c!200","b c",700);   // Middle
        assertMetrics("weight:0.2857","a b c!200","a b",700);   // Worst

        assertMetrics("weight:0.6667","a!300 b c!200","a b c",900); // Better than best

        assertMetrics("weight:0.4545","a b c!50","a b c",550); // Best
        assertMetrics("weight:0.2727","a b c!50","b c",550);   // Worse
        assertMetrics("weight:0.1818","a b c!50","b",550);     // Worse
        assertMetrics("weight:0.0909","a b c!50","c",550);     // Worst
        assertMetrics("weight:0.3636","a b c!50","a b",550);   // Middle

        assertMetrics("weight:0.4","a b c!0","a b c",500);  // Best
        assertMetrics("weight:0.2","a b c!0","b c",500);  // Worst
        assertMetrics("weight:0.4","a b c!0","a b",500);    // As good as best
        assertMetrics("weight:0",  "a b c!0","c",500);      // No contribution

        assertMetrics("weight:0","a!0 b!0","a b",300);
        assertMetrics("weight:0","a!0 b!0","",300);
    }
Tests of calculation of all the string match metrics.
Add true as the fourth parameter to assertMetrics to see a trace of what the test is doing.

@author bratseth
searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/test/FieldMatchMetricsTestCase.java