package edu.columbia.cs.cs1007.roster;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.FileNotFoundException;
import java.io.IOException;

import org.junit.Test;

public class SortTester {

  @Test(expected=IllegalArgumentException.class)
  public void testParsing() throws NumberFormatException, 
                   FileNotFoundException, 
                   IOException {
    Roster roster = new Roster();    
    String[] args = {"-i""students.txt""-o",  "student_uni.txt",  "-s""blah"};

    roster.parseArguments(args);
  }
  
  @Test
  //@Ignore
  public void testUniSort() throws NumberFormatException, 
                   FileNotFoundException, 
                   IllegalArgumentException, 
                   IOException {
    
    Roster roster = new Roster();    
    String[] args = {"-i""students.txt""-o",  "student_uni.txt",  "-s""uni"};
    
    roster.parseArguments(args);
    roster.readInput();
    Student[] students = roster.sort();
    assertEquals(21, roster.getNumStudents());
     
    assertTrue(students[0].getUni().equalsIgnoreCase("abg2131"));
    assertTrue(students[5].getUni().equalsIgnoreCase("crw2124"));
  }

  @Test
  public void testYearSort() throws NumberFormatException, 
                     FileNotFoundException, 
                     IllegalArgumentException, 
                     IOException {    
    Roster roster = new Roster();    
    String[] args = {"-i""students.txt""-o",  "student_uni.txt",  "-s""year"};
    
    roster.parseArguments(args);
    roster.readInput();
    Student[] students = roster.sort();
    
    assertEquals(21, roster.getNumStudents());
    assertTrue(students[0].getGradYear() == 2009);
    // why is this not a good test case?
    assertTrue(students[5].getUni().equalsIgnoreCase("zms2105"));
  }

}