/*
 * Created on Feb 26, 2004
 */
package lotto.test;

import java.io.*;

import com.sun.rsasign.s;

import junit.framework.TestCase;
import lotto.Schein;

/**
 * @author oliver (boehm@javatux.de)
 */
public class ScheinTest extends TestCase {
    
    private Schein schein;
    private Reader reader;

    /**
     * Constructor for ScheinTest.
     * @param arg0
     */
    public ScheinTest(String arg0) {
        super(arg0);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(ScheinTest.class);
    }

    /*
     * @see TestCase#setUp()
     */
    protected void setUp() throws Exception {
        reader = new FileReader("Lotto.schein");
        schein = new Schein();
    }
    
    protected void tearDown() throws Exception {
        reader.close();
    }

    /**
     * Liest eine Karte aus "Lotto.schein" und ueberprueft sie.
     * @throws IOException
     */
    final public void testRead() throws IOException {
        schein.read(reader);
        assertEquals("Anna", schein.getSpieler());
        int[] tip = schein.getTip();
        assertEquals(3, tip[0]);
        assertEquals(46, tip[5]);
        assertEquals(42, schein.getZusatzzahl());
    }
    
    /**
     * Liest den 2. Satz aus "Lotto.schein" und ueberprueft ihn.
     * @throws IOException
     */
    final public void testRead2() throws IOException {
        schein.read(reader);
        schein.read(reader);
        assertEquals("Berta", schein.getSpieler());
        int[] tip = schein.getTip();
        assertEquals(11, tip[0]);
        assertEquals(46, tip[5]);
        assertEquals(35, schein.getZusatzzahl());        
    }
    
    final public void testReadLast() throws IOException {
        for (int i = 0; i < 26; i++) {
            schein.read(reader);
        }
        assertEquals("Zoro", schein.getSpieler());
        assertEquals(12, schein.getZusatzzahl());
    }
    
    /**
     * 52 Saetze sind in der Test-Datei. Wird auch tatsaechlich 26 mal ein
     * Schein eingelesen?
     */
    final public void testReadAll() {
        int n = 0;
        try {
            for (n = 0; ;n++) {
                schein.read(reader);
            }
        } catch (IOException expected) {}
        assertEquals(53, n);
    }
    
    final public void testGetRichtige() {
        int[] gezogen = {1, 2, 3, 4, 5, 6};
        schein.setTip(1, 2, 3, 4, 5, 6);
        assertEquals(6, schein.getNoRichtige(gezogen));
        schein.setTip(7, 8, 9, 10, 11, 12);
        assertEquals(0, schein.getNoRichtige(gezogen));
        schein.setTip(6, 7, 8, 9, 10, 11);
        assertEquals(1, schein.getNoRichtige(gezogen));
    }

}
