package org.jenkinsci.plugins.categoriesreport;

import junit.framework.TestCase;

import java.util.ArrayList;
import java.util.List;

public class CategoriesResultTest extends TestCase {

    public void testAccumulationIsDoneCorrectly() {
        CategoryResult cr1 = new CategoryResult("1");
        cr1.addSuccesses(125);
        cr1.addFailures(562);

        CategoryResult cr2 = new CategoryResult("2");
        cr2.addSuccesses(137);
        cr2.addFailures(859);

        List<CategoryResult> cr = new ArrayList<CategoryResult>();
        cr.add(cr1);
        cr.add(cr2);

        CategoriesResult result = new CategoriesResult(cr);
        assertEquals(262, result.getSuccesses());
        assertEquals(1421, result.getFailures());
        assertEquals(1683, result.getTotal());
        assertEquals(0.16d, result.getSuccessPercentage(), 0.01);
        assertEquals(0.84d, result.getFailurePercentage(), 0.01);
    }

    public void testBackgroundColorsAreDifferentBetweenSuccessAndFailure() {
        CategoryResult successResult = new CategoryResult("1");
        successResult.addFailures(0);
        successResult.addSuccesses(562);

        CategoryResult failureResult = new CategoryResult("2");
        failureResult.addFailures(1);
        failureResult.addSuccesses(859);

        List<CategoryResult> cr = new ArrayList<CategoryResult>();
        cr.add(successResult);
        cr.add(failureResult);

        CategoriesResult result = new CategoriesResult(cr);

        String successColor = result.getForegroundColor(successResult);
        String failureColor = result.getForegroundColor(failureResult);

        assertNotSame(successColor, failureColor);
    }

    public void testFormatForNo() {
        List<CategoryResult> cr = new ArrayList<CategoryResult>();

        CategoriesResult result = new CategoriesResult(cr);

        assertEquals("100%", result.format(1.0d));
        assertEquals("<100%", result.format(0.999d));
        assertEquals("98%", result.format(0.98d));
        assertEquals("2%", result.format(0.02d));
        assertEquals(">0%", result.format(0.001d));
        assertEquals("0%", result.format(0d));
    }
}

@@ -1949,16 +1949,23 @@
 mat(1.0d
+, false
 ));%0D%0A   
@@ -2011,16 +2011,23 @@
 t(0.999d
+, false
 ));%0D%0A   
@@ -2070,16 +2070,23 @@
 at(0.98d
+, false
 ));%0D%0A   
@@ -2128,16 +2128,23 @@
 at(0.02d
+, false
 ));%0D%0A   
@@ -2188,16 +2188,23 @@
 t(0.001d
+, false
 ));%0D%0A   
@@ -2243,16 +2243,557 @@
 ormat(0d
+, false));%0D%0A    %7D%0D%0A%0D%0A    public void testFormatForNoAlternate() %7B%0D%0A        List%3CCategoryResult%3E cr = new ArrayList%3CCategoryResult%3E();%0D%0A%0D%0A        CategoriesResult result = new CategoriesResult(cr);%0D%0A%0D%0A        assertEquals(%22100%25%22, result.format(1.0d, true));%0D%0A        assertEquals(%22%3E99%25%22, result.format(0.999d, true));%0D%0A        assertEquals(%2298%25%22, result.format(0.98d, true));%0D%0A        assertEquals(%222%25%22, result.format(0.02d, true));%0D%0A        assertEquals(%22%3C1%25%22, result.format(0.001d, true));%0D%0A        assertEquals(%220%25%22, result.format(0d, true
 ));%0D%0A   

fix unit test compilation