Files
cs6601p3/test/net/woodyfolsom/cs6601/p3/dao/MySQLHeadlineDaoImplTest.java

55 lines
1.8 KiB
Java

package net.woodyfolsom.cs6601.p3.dao;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import net.woodyfolsom.cs6601.p3.svc.HeadlineService;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class MySQLHeadlineDaoImplTest {
private static HeadlineService headlineSvc;
@BeforeClass
public static void setUp() {
ApplicationContext context=new FileSystemXmlApplicationContext(new String[]{"AppContext.xml"});
headlineSvc = (HeadlineService) context
.getBean("mySQLHeadlineSvc");
}
@Test
public void testSelect() {
assertNotNull(headlineSvc);
}
//Change this back to @Test to run it... but beware, it shuffles the datasets. Best done n times for n-fold cross validation.
@Ignore
public void testAssignRandomDatasets() {
int trainingPct = 80;
int testPct = 10;
int valPct = 10;
//assignment fails if character is ommitted from valPct (80% 10% 1% by accident)
assertFalse(headlineSvc.assignRandomDatasets(trainingPct,testPct,valPct/10));
//assignment succeeds if requested ratio is 8-1-1
assertTrue(headlineSvc.assignRandomDatasets(trainingPct,testPct,valPct));
int allCount = headlineSvc.getCount();
int trainingCount = headlineSvc.getCount(1);
int testCount = headlineSvc.getCount(2);
int valCount = headlineSvc.getCount(3);
assertEquals(trainingCount + testCount + valCount, allCount);
assertEquals((double)trainingCount/allCount,(double)trainingPct / 100.0,0.01);
assertEquals((double)testCount/allCount,(double)testPct / 100.0,0.01);
assertEquals((double)valCount/allCount,(double)valPct / 100.0,0.01);
}
}