(This should not need to happen). PricePoller and ValidationSetCreator generate the 1, 2, 3-grams.txt and validation.txt files, respectively. MySQLHeadlineDaoImplTest reshuffles the training, validation datasets in 60-40 ratio.
55 lines
1.8 KiB
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.
|
|
@Test
|
|
public void testAssignRandomDatasets() {
|
|
|
|
int trainingPct = 60;
|
|
//int testPct = 10;
|
|
int valPct = 40;
|
|
|
|
//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);
|
|
}
|
|
}
|