Skip to content

Commit

Permalink
port testDecoding() and not passed yet
Browse files Browse the repository at this point in the history
  • Loading branch information
utensil committed Jan 2, 2015
1 parent 5fb02f6 commit 7c3d7d1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
Expand Up @@ -598,7 +598,7 @@ public boolean eval(int n) {
String desc = generateRangeDescription(ranges);
String fieldName;
// Return result
if(!parentFieldName.isEmpty()) {
if(parentFieldName != null && !parentFieldName.isEmpty()) {
fieldName = String.format("%s.%s", parentFieldName, getName());
}else{
fieldName = getName();
Expand Down
44 changes: 41 additions & 3 deletions src/test/java/org/numenta/nupic/encoders/DateEncoderTest.java
@@ -1,8 +1,6 @@
package org.numenta.nupic.encoders;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;

import org.joda.time.DateTime;
import org.junit.Test;
Expand All @@ -11,6 +9,7 @@
import org.numenta.nupic.util.Tuple;

import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;

public class DateEncoderTest {
private DateEncoder de;
Expand Down Expand Up @@ -95,5 +94,44 @@ public void testDateEncoder() {
de.pprint(bits, "");
System.out.println();
}

//TODO testMissingValues in Python can't be ported
// because SENTINEL_VALUE_FOR_MISSING_DATA is not a Date

/**
* Decoding date
*/
@Test
public void testDecoding() {
setUp();
initDE();

Tuple decoded = de.decode(bits, null);

Map<String, Tuple> fieldsMap = (Map<String, Tuple>)decoded.get(0);
List<String> fieldsOrder = (List<String>)decoded.get(1);

assertNotNull(fieldsMap);
assertNotNull(fieldsOrder);
assertEquals(4, fieldsMap.size());

//TODO can't assert on the length of Tuple yet

Map<String, Tuple> expectedFieldsMap = new HashMap<>();
expectedFieldsMap.put("season", new Tuple(2, 305.0, 305.0));
expectedFieldsMap.put("time of day", new Tuple(2, 14.4, 14.4));
expectedFieldsMap.put("day of week", new Tuple(2, 3.0, 3.0));
expectedFieldsMap.put("weekend", new Tuple(2, 0.0, 0.0));

// for (String key : expectedFieldsMap.keySet()) {
// Tuple expected = expectedFieldsMap.get(key);
// Tuple actual = fieldsMap.get(key);
// assertEquals(expected, actual);
// }

System.out.println(decoded.toString());
System.out.println(String.format("decodedToStr=>%s", de.decodedToStr(decoded)));
}

}

0 comments on commit 7c3d7d1

Please sign in to comment.