Skip to content
Snippets Groups Projects
Commit 63ab67f3 authored by Marcelo's avatar Marcelo
Browse files

normalize class working, 3 tests pass testing

Parser.normalize
parent edb3c003
No related branches found
No related tags found
No related merge requests found
package edu.odu.cs.cs350.acmClassifier;
import java.util.ArrayList;
//import java.util.ArrayList;
public class Parser {
......@@ -19,17 +19,29 @@ public class Parser {
* @param Document object
**/
//public ArrayList<Integer> normalize(ArrayList<Integer> signatures){
/*
public static ArrayList<Integer > normalize(Document d){
for (int i = 0; i < d.wordCounts.size(); i++) {
if (d.wordCounts.get(i) >= 4){
d.wordCounts.set(i, 1);
}
}
else{
d.wordCounts.set(i, 0);
}
}
return d.wordCounts;
}
*/
public static void normalize(Document d){
for (int i = 0; i < d.wordCounts.size(); i++){
if (d.wordCounts.get(i) >= 4){
d.normalizedWordCounts.add(1.0);
}
else{
d.normalizedWordCounts.add(0.0);
}
}
}
}
package edu.odu.cs.cs350.acmClassifier;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
public class TestParser {
/*
* expected normalized word counts
*/
private Double[] normalized1 = {1.0, 1.0, 1.0, 1.0};
private Double[] normalized2 = {0.0, 0.0, 0.0, 0.0};
private Double[] normalized3 = {1.0, 1.0, 0.0, 0.0};
/*
* sample word counts
*/
private Integer[] sampleWC1 = {4, 5, 7, 9};
private Integer[] sampleWC2 = {3, 2, 1, 2};
private Integer[] sampleWC3 = {6, 5, 1, 1};
@Test
void TestParser(){
fail("Not yet implemented");
}
*/
public void testNormalize1(){
Document test1;
Document test1 = new Document();
@BeforeAll
public void init(){
test1 = new Document();
//ArrayList<Integer> this.wordCounts = new ArrayList<Integer>();
test1.wordCounts = new ArrayList<Integer>(Arrays.asList(sampleWC1));
Parser.normalize(test1);
ArrayList<Double> expected = new ArrayList<Double>(Arrays.asList(normalized1));
assertEquals(expected, test1.normalizedWordCounts);
}
@Test
public void testNormalize1(){
public void testNormalize2(){
Document test2 = new Document();
test2.wordCounts = new ArrayList<Integer>(Arrays.asList(sampleWC2));
//Document test1 = new Document();
//test1 = new Document();
Parser.normalize(test2);
//ArrayList<String> test1.wordCounts = new ArrayList<String>();
ArrayList<Double> expected = new ArrayList<Double>(Arrays.asList(normalized2));
//test1.wordCounts = new ArrayList<>();
assertEquals(expected, test2.normalizedWordCounts);
test1.wordCounts.add(4);
test1.wordCounts.add(3);
test1.wordCounts.add(5);
test1.wordCounts.add(2);
test1.wordCounts.add(1);
}
@Test
public void testNormalize3(){
Document test3 = new Document();
ArrayList<Integer> expected = new ArrayList<Integer>();
test3.wordCounts = new ArrayList<Integer>(Arrays.asList(sampleWC3));
for (int i = 0; i < 5; i++){
expected.add(1);
}
Parser.normalize(test3);
assertEquals(expected, Parser.normalize(test1));
//assertArrayEquals(expected, Parser.normalize(test1));
ArrayList<Double> expected = new ArrayList<Double>(Arrays.asList(normalized3));
assertEquals(expected, test3.normalizedWordCounts);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment