class DrawMargin {

    public static double GetDrawMarginFromDrawProbability(double drawProbability, double beta) {

        /*
         * Derived from TrueSkill technical report (MSR-TR-2006-80), page 6
         *
         * draw probability = 2 * CDF(margin/(sqrt(n1+n2)*beta)) -1
         * implies
         * margin = inversecdf((draw probability + 1)/2) * sqrt(n1+n2) * beta
         * where n1 and n2 are the number of players on each team
         */
        return inverseCumulativeTo(.5 * (drawProbability + 1), 0, 1) * Math.sqrt(1 + 1) * beta;
    }

}

class DrawMarginTest {

    private static final double ErrorTolerance;

    @Test
    public void GetDrawMarginFromDrawProbabilityTest() {

        double beta = 25.0 / 6.0;
        // The expected values were compared against Ralf Herbrich's implementation in F#
        AssertDrawMargin(0.10, beta, 0.74046637542690541);
        AssertDrawMargin(0.25, beta, 1.87760059883033);
        AssertDrawMargin(0.33, beta, 2.5111010132487492);
    }

}