package com.ybrikman.funky.tictactoe;

import com.pholser.junit.quickcheck.ForAll;
import org.junit.Test;
import org.junit.contrib.theories.*;
import org.junit.runner.RunWith;
import java.util.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
/**
 * Created by cody on 11/28/14.
 */
@RunWith(Theories.class)
public class BoardMathHelperPropertyTests
{
    //Tests that every return value of this function has greater than 0 digits
    @Test @Theory public void testNumberOfDigitsProperty(@ForAll int num)
    {
        assumeThat(num ,any(Integer.TYPE));
        int digits=BoardMathHelpers.numberOfDigits(num);
        assertTrue(digits>0);

    }
    @Test @Theory public void testIsPerfectSquare(@ForAll int num)
    {
        assumeThat(num,any(Integer.TYPE));
        boolean ans=BoardMathHelpers.isPerfectSquare(num);
        Integer sqrt = (int)(Math.sqrt(num)+0.5);
        if(ans) {

            assertEquals(num, sqrt * sqrt);
        }
        else {
            assertNotEquals(num, sqrt * sqrt);
        }

    }
    @Test @Theory public void testDefaultBoardSizeProperty()
    {
       List<java.util.Optional<Player>> board=BoardMathHelpers.defaultBoard();
       assertTrue(board.size()==BoardMathHelpers.getDefaultBoardSize());

    }
    @Test @Theory public void testCalculateWinningRowIndicesSizes()
    {
        int rowSize=3;
        List<List<Integer>> indices = BoardMathHelpers.calculateWinningRowIndices(rowSize*rowSize,rowSize);

        //Each list of winning indices should be the length of rowSize
        for(List<Integer> index : indices) {
            assertEquals(index.size(), rowSize);
        }


    }

}

@@ -76,16 +76,71 @@
 ForAll;%0A
+import com.pholser.junit.quickcheck.generator.InRange;%0A
 import o
@@ -539,16 +539,69 @@
  digits%0A
+    //It is impossible to have an int with no digits%0A
     @Tes
@@ -802,32 +802,223 @@
 gits%3E0);%0A%0A    %7D%0A
+    /*%0A     *  Tests the boolean answer of the function%0A     *  This test was difficult for testing properties without%0A     *  implementing the actual function, since it is so simple%0A     */%0A
     @Test @Theor
@@ -1370,32 +1370,209 @@
        %7D%0A%0A    %7D%0A
+    /*%0A     *  Tests the size of the List returned by the defaultBoard() function%0A     *  The List size should match the DEFAULT_BOARD_SIZE constant in BoardMathHelpers%0A     */%0A
     @Test @Theor
@@ -1714,20 +1714,22 @@
   assert
-True
+Equals
 (board.s
@@ -1737,10 +1737,10 @@
 ze()
-==
+, 
 Boar
@@ -1779,24 +1779,531 @@
 ());%0A%0A    %7D%0A
+    /*%0A     *  ARGS- Keep rowSize in the range of 2 to 100 for reasonable values%0A     *          (Playing with a board size less than 2 is pointless and playing with%0A     *           a board size greater than 100 is highly unlikely)%0A     *  The method Tests the size of each List of winning indices%0A     *  In order to win tic-tac-toe, the winning combination needs to be exactly%0A     *  the length of one side of the tic-tac-toe board, going either diagonally,%0A     *  vertically, or horizontally.%0A     */%0A
     @Test @T
@@ -2356,32 +2356,54 @@
 esSizes(
-)%0A    %7B%0A        
+@ForAll @InRange(minInt=2, maxInt=100)
 int rowS
@@ -2409,11 +2409,15 @@
 Size
-=3;
+)%0A    %7B
 %0A   
@@ -2521,17 +2521,16 @@
 wSize);%0A
-%0A
         

Add comments