/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira.junit
 */
package net.ranides.assira.junit;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class BenchmarkReportTest {
    
    private static final String INPUT =
        "     0% Scenario{vm=java, trial=0, benchmark=ListThread} 12741,34 ns; ?=252,99 ns @ 20 trials\n"+
        "    4% Scenario{vm=java, trial=1, benchmark=ListThread} 10735,86 ns; ?=29,81 ns @ 1 trials\n"+
        "    8% Scenario{vm=java, trial=2, benchmark=ListThread} 10624,55 ns; ?=70,86 ns @ 1 trials\n"+
        "   13% Scenario{vm=java, trial=0, benchmark=CallerThread} 13616,58 ns; ?=36,58 ns @ 3 trials\n"+
        "   17% Scenario{vm=java, trial=1, benchmark=CallerThread} 13677,01 ns; ?=66,01 ns @ 3 trials\n"+
        "   21% Scenario{vm=java, trial=2, benchmark=CallerThread} 13852,23 ns; ?=63,15 ns @ 3 trials\n"+
        "   25% Scenario{vm=java, trial=0, benchmark=CallerSecurityManager} 826,64 ns; ?=1,84 ns @ 3 trials\n"+
        "   29% Scenario{vm=java, trial=1, benchmark=CallerSecurityManager} 816,69 ns; ?=3,84 ns @ 3 trials\n"+
        "   33% Scenario{vm=java, trial=2, benchmark=CallerSecurityManager} 817,24 ns; ?=3,19 ns @ 3 trials\n"+
        "   38% Scenario{vm=java, trial=0, benchmark=CallerSunReflect} 142,74 ns; ?=1,38 ns @ 5 trials\n"+
        "   42% Scenario{vm=java, trial=1, benchmark=CallerSunReflect} 145,95 ns; ?=1,77 ns @ 10 trials\n"+
        "   46% Scenario{vm=java, trial=2, benchmark=CallerSunReflect} 143,09 ns; ?=1,15 ns @ 3 trials\n"+
        "   50% Scenario{vm=java, trial=0, benchmark=ListException} 12035,15 ns; ?=43,56 ns @ 3 trials\n"+
        "   54% Scenario{vm=java, trial=1, benchmark=ListException} 12095,09 ns; ?=109,92 ns @ 3 trials\n"+
        "   58% Scenario{vm=java, trial=2, benchmark=ListException} 12086,37 ns; ?=65,36 ns @ 3 trials\n"+
        "   63% Scenario{vm=java, trial=0, benchmark=CallerException} 12985,63 ns; ?=145,23 ns @ 10 trials\n"+
        "   67% Scenario{vm=java, trial=1, benchmark=CallerException} 12959,19 ns; ?=63,32 ns @ 3 trials\n"+
        "   71% Scenario{vm=java, trial=2, benchmark=CallerException} 12881,98 ns; ?=68,18 ns @ 3 trials\n"+
        "   75% Scenario{vm=java, trial=0, benchmark=ListSunReflect} 3754,91 ns; ?=37,69 ns @ 4 trials\n"+
        "   79% Scenario{vm=java, trial=1, benchmark=ListSunReflect} 3862,52 ns; ?=37,97 ns @ 7 trials\n"+
        "   83% Scenario{vm=java, trial=2, benchmark=ListSunReflect} 3883,26 ns; ?=29,84 ns @ 3 trials\n"+
        "   88% Scenario{vm=java, trial=0, benchmark=ListSecurityManager} 815,23 ns; ?=1,44 ns @ 3 trials\n"+
        "   92% Scenario{vm=java, trial=1, benchmark=ListSecurityManager} 821,71 ns; ?=8,04 ns @ 3 trials\n"+
        "   96% Scenario{vm=java, trial=2, benchmark=ListSecurityManager} 814,32 ns; ?=2,53 ns @ 3 trials\n";
    
    private static final String EXPECTED = 
        "CallerException          = 12961 ? 10%n"+
        "CallerSecurityManager    =   820 ? 2%n"+
        "CallerSunReflect         =   145 ? 0%n"+
        "CallerThread             = 13715 ? 33%n"+
        "ListException            = 12072 ? 9%n"+
        "ListSecurityManager      =   817 ? 1%n"+
        "ListSunReflect           =  3836 ? 14%n"+
        "ListThread               = 12554 ? 126%n";
    
    @Test
    public void testManual() {
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        BenchmarkReport.print(new PrintStream(ostream), INPUT);

//        System.out.printf(">>>%n%s<<<%n", ostream.toString());
        assertEquals(String.format(EXPECTED), ostream.toString());
    }
    
}
