001/*
002 * $Id$
003 */
004
005package edu.jas.application;
006
007
008import java.io.ByteArrayOutputStream;
009import java.io.PrintStream;
010
011import edu.jas.kern.ComputerThreads;
012
013import junit.framework.Test;
014import junit.framework.TestCase;
015import junit.framework.TestSuite;
016
017
018/**
019 * CLI tests with JUnit for GBs.
020 * @author Heinz Kredel
021 */
022
023public class RunSGBTest extends TestCase {
024
025
026    /**
027     * main.
028     */
029    public static void main(String[] args) {
030        junit.textui.TestRunner.run(suite());
031    }
032
033
034    /**
035     * Constructs a <CODE>RunSGBTest</CODE> object.
036     * @param name String.
037     */
038    public RunSGBTest(String name) {
039        super(name);
040    }
041
042
043    /**
044     */
045    public static Test suite() {
046        TestSuite suite = new TestSuite(RunSGBTest.class);
047        return suite;
048    }
049
050
051    @Override
052    protected void setUp() {
053    }
054
055
056    @Override
057    protected void tearDown() {
058        ComputerThreads.terminate();
059    }
060
061
062    /**
063     * Test sequential GB.
064     */
065    public void testSequentialGB() {
066        RunSGB cli = new RunSGB();
067        PrintStream ps = System.out;
068        ByteArrayOutputStream bs = new ByteArrayOutputStream();
069        PrintStream ss = new PrintStream(bs);
070        try {
071            System.setOut(ss);
072            cli.main(new String[] { "seq", "left", "examples/wa_32.jas", "check" });
073        } finally {
074            System.setOut(ps);
075        }
076        String sto = bs.toString();
077        //System.out.println(sto);
078        assertTrue("sequential", sto.contains("sequential"));
079        assertTrue("G.size() = 5", sto.contains("G.size() = 5"));
080        assertTrue("check isGB = true", sto.contains("check isGB = true"));
081    }
082
083
084    /**
085     * Test sequential two-sided GB.
086     */
087    public void testSequential2tsGB() {
088        RunSGB cli = new RunSGB();
089        PrintStream ps = System.out;
090        ByteArrayOutputStream bs = new ByteArrayOutputStream();
091        PrintStream ss = new PrintStream(bs);
092        try {
093            System.setOut(ss);
094            cli.main(new String[] { "seq", "two", "examples/wa_32.jas", "check" });
095        } finally {
096            System.setOut(ps);
097        }
098        String sto = bs.toString();
099        //System.out.println(sto);
100        assertTrue("sequential", sto.contains("sequential"));
101        assertTrue("two", sto.contains("two"));
102        assertTrue("G.size() = 5", sto.contains("G.size() = 5"));
103        assertTrue("check isGB = true", sto.contains("check isGB = true"));
104    }
105
106
107    /**
108     * Test parallel left GB.
109     */
110    public void testParallelLeftGB() {
111        RunSGB cli = new RunSGB();
112        PrintStream ps = System.out;
113        ByteArrayOutputStream bs = new ByteArrayOutputStream();
114        PrintStream ss = new PrintStream(bs);
115        try {
116            System.setOut(ss);
117            cli.main(new String[] { "par", "left", "examples/wa_1.jas", "3", "check" });
118        } finally {
119            System.setOut(ps);
120        }
121        String sto = bs.toString();
122        //System.out.println(sto);
123        assertTrue("parallel", sto.contains("parallel"));
124        assertTrue("left", sto.contains("left"));
125        assertTrue("G.size() = 8", sto.contains("G.size() = 8"));
126        assertTrue("check isGB = true", sto.contains("check isGB = true"));
127    }
128
129}