Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

Fixture - Find Highest Number Only

FindHighestNumberFixture.java
package com.celestial.tdd.fitnesse.demo;

import com.celestial.tdd.demo.complete.ArrayUtils;
import com.celestial.tdd.demo.complete.EmptyArrayException;
import java.util.Arrays;

/**
 *
 * @author Selvyn
 */
public class FindHighestNumberFixture
{
    int[] arrayOfInts;
    
    public  void    setNumbers( String vals )
    {
        arrayOfInts = Arrays.stream(vals.split(","))
                 .mapToInt(Integer::parseInt)
                 .toArray();
    }
    
    public  int  ExpectedValue()
    {
        ArrayUtils cut = new ArrayUtils();
        
        try
        {
            return cut.findHighest(arrayOfInts);
        } catch (EmptyArrayException ex)
        {
            return -1;
        }
    }
    
    public  void    setNumbersList( int[] vals )
    {
        arrayOfInts = vals;
    }
}

Notice I am making use of ArrayUtils from the unit testing phase.

Fixture - Find Highest Number and Sort List (no reuse of CUT)

FindHighestNumberAndSortArrayFixture
package com.celestial.tdd.fitnesse.demo;

import com.celestial.tdd.demo.complete.ArrayUtils;
import com.celestial.tdd.demo.complete.EmptyArrayException;
import java.util.Arrays;

/**
 *
 * @author Selvyn
 */
public class FindHighestNumberAndSortArrayFixture
{
    int[] arrayOfInts;
    
    public  void    setNumbers( String vals )
    {
        arrayOfInts = Arrays.stream(vals.split(","))
                 .mapToInt(Integer::parseInt)
                 .toArray();
    }
    
    public  int  ExpectedValue()
    {
        ArrayUtils cut = new ArrayUtils();
        
        try
        {
            return cut.findHighest(arrayOfInts);
        } catch (EmptyArrayException ex)
        {
            return -1;
        }
    }
    
    public  void    setNumbersList( int[] vals )
    {
        arrayOfInts = vals;
    }
    
    public  String SortedList()
    {
        ArrayUtils cut = new ArrayUtils();
        
        int[] intArray = cut.sortedArray( arrayOfInts );
        
        String temp =  Arrays.toString(intArray);
        temp = temp.replaceAll("[\\[\\s\\]]", "");

        return temp;
    }
}
  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.