Example #1
0
void testMultipleDeathListeners()
{
	TEST_SETUP();

	song_iterator_add_death_listener(
			it,
			it,
			(void (*)(void *, void*))DeathListenerCallback);

	song_iterator_add_death_listener(
			it,
			it,
			(void (*)(void *, void*))DeathListenerCallback);

	for (i=0; i < SONG_CMD_COUNT; i++)
	{
		message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL);
	}

	TESTEQUAL(SI_FINISHED, message);

	TEST_TEARDOWN();

	TESTEQUAL(2, calledDeathListenerCallback);
}
Example #2
0
 void TesterTest::RunTestsShouldFail()
 {
   // These are probably the only tests in our test suite that should fail.
   TESTEQUAL2("Integer test, should fail",1,0);
   TESTEQUAL2("Double test, should fail",23.42,23.421);
   TESTEQUAL2_STR("String test, should fail","Numenta","Numenta ");
   TESTEQUAL(1,0);
   TESTEQUAL(23.42,23.421);
   EXPECT_STREQ("Numenta","Numenta ");
   TEST(false);
   TEST2("TEST2(false)", false);    
 }
Example #3
0
void testChangeSongMask()
{
	TEST_SETUP();

	message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL);
	TESTEQUAL(0xAA, message);

	SIMSG_SEND(it, SIMSG_SET_PLAYMASK(0x40));
	message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL);
	TESTEQUAL(0, message);
	TESTEQUAL(0, result);

	TEST_TEARDOWN();
}
Example #4
0
void testStopLoopedSong()
{
	TEST_SETUP();

	SIMSG_SEND(it, SIMSG_SET_LOOPS(3));
	message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL);
	TESTEQUAL(0xAA, message);

	SIMSG_SEND(it, SIMSG_STOP);
	message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL);
	TESTEQUAL(SI_FINISHED, message);

	TEST_TEARDOWN();
}
 void CondProbTableTest::testVectors(const string& testName, const vector<Real>& v1,
                                     const vector<Real>& v2)
 {
   stringstream s1, s2;
   s1 << v1;
   s2 << v2;
   TESTEQUAL(s1.str(), s2.str());
 }
Example #6
0
void testFinishSong()
{
	TEST_SETUP();
	message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL);
	TESTEQUAL(0xAA, message);

	message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL);
	TESTEQUAL(0, message);
	TESTEQUAL(3, result);

	for (i=0; i < SONG_CMD_COUNT - 2; i++)
	{
		message = songit_next(&it, &cmds, &result, IT_READER_MASK_ALL);
	}

	TESTEQUAL(SI_FINISHED, message);

	TEST_TEARDOWN();
}
Example #7
0
  // Run all appropriate tests
  void TesterTest::RunTests()
  {

    TESTEQUAL2("Integer test, should succeed",1,1);
    TESTEQUAL2("Double test, should succeed",23.42,23.42);
    TESTEQUAL2_STR("String test, should succeed","Numenta","Numenta");

    // Repeat the above for TESTEQUAL
    TESTEQUAL(1,1);
    TESTEQUAL(23.42,23.42);
    EXPECT_STREQ("Numenta","Numenta");
    
    // Test functions in Common
    TESTEQUAL2("Max test", 23.3, Max(23.2, 23.3));
    TESTEQUAL2("Min test", 23.2, Min(23.2, 23.3));
    TESTEQUAL2("Max test", 'b', Max('a', 'b'));
    TESTEQUAL2("Min test", 'a', Min('a', 'b'));

    // Repeat the above for TESTEQUAL
    TESTEQUAL(23.3, Max(23.2, 23.3));
    TESTEQUAL(23.2, Min(23.2, 23.3));
    TESTEQUAL('b', Max('a', 'b'));
    TESTEQUAL('a', Min('a', 'b'));

    // TESTEQUAL_FLOAT allows error less than 0.000001
    TESTEQUAL_FLOAT(23.42,23.4200009);

    // Tests for TEST
    TEST(true);  
    TEST2("TEST2(true)", true);  

    // Tests for throws  
    nupic::LoggingException e(__FILE__, __LINE__);
    e << "This exception should be thrown.";

    SHOULDFAIL(throw e);  
    SHOULDFAIL_WITH_MESSAGE(
      throw e,
      "This exception should be thrown.");
  }
Example #8
0
  //----------------------------------------------------------------------
  void CondProbTableTest::testTable(const string& testName, CondProbTable& table, 
                                    const vector<vector<Real> > & rows)
  {
  
    // Test the numRows(), numCols() calls
    TESTEQUAL(numRows(), table.numRows());
    TESTEQUAL(numCols(), table.numColumns());

    // See if they got added right
    vector<Real>  testRow(numCols());
    for (Size i=0; i<numRows(); i++) {
      stringstream ss;
      ss << "updateRow " << i;
    
      table.getRow((UInt)i, testRow);
      testVectors(testName+ss.str(), rows[i], testRow);
    }


    // --------------------------------------------------------------------
    // Try out normal inference
    vector<Real> expValue;
    vector<Real> output(numRows());
  
    // Row 0 matches row 3, so we get half and half hits on those rows
    table.inferRow (rows[0], output, CondProbTable::inferMarginal);
    testVectors(testName+"row 0 infer", makeCol((Real).16, (Real)0, (Real)0, (Real).24), output);
  
    // Row 1 matches only row 1
    table.inferRow (rows[1], output, CondProbTable::inferMarginal);
    testVectors(testName+"row 1 infer", makeCol((Real)0, 1, (Real)0, (Real)0), output);

    // Row 2 matches only row 2 and 3
    table.inferRow (rows[2], output, CondProbTable::inferMarginal);
    testVectors(testName+"row 2 infer", makeCol((Real)0, (Real)0, (Real).36, (Real).24), output);

    // Row 3 matches row 0 & row 2 halfway, and row 3 exactly
    table.inferRow (rows[3], output, CondProbTable::inferMarginal);
    testVectors(testName+"row 3 infer", makeCol((Real).24, (Real)0, (Real).24, (Real).52), output);
  
  
    // --------------------------------------------------------------------
    // Try out inferEvidence inference
  
    // Row 0 matches row 0 and half row 3, so we get half and half hits on those rows
    table.inferRow (rows[0], output, CondProbTable::inferRowEvidence);
    testVectors(testName+"row 0 inferEvidence", makeCol((Real).4, (Real)0, (Real)0, (Real).24), output);
  
    // Row 1 matches only row 1
    table.inferRow (rows[1], output, CondProbTable::inferRowEvidence);
    testVectors(testName+"row 1 inferEvidence", makeCol((Real)0, 1, (Real)0, (Real)0), output);

    // Row 2 matches only row 2 and half row 3
    table.inferRow (rows[2], output, CondProbTable::inferRowEvidence);
    testVectors(testName+"row 2 inferEvidence", makeCol((Real)0, (Real)0, (Real).6, (Real).24), output);

    // Row 3 matches row 0 & row 2 halfway, and row 3 exactly
    table.inferRow (rows[3], output, CondProbTable::inferRowEvidence);
    testVectors(testName+"row 3 inferEvidence", makeCol((Real).6, (Real)0, (Real).4, (Real).52), output);
  
  
    // --------------------------------------------------------------------
    // Try out inferMaxProd inference
  
    // Row 0 matches row 0 and half row 3, so we get half and half hits on those rows
    table.inferRow (rows[0], output, CondProbTable::inferMaxProd);
    testVectors(testName+"row 0 inferMaxProd", makeCol((Real).16, (Real)0, (Real)0, (Real).24), output);
  
    // Row 1 matches only row 1
    table.inferRow (rows[1], output, CondProbTable::inferMaxProd);
    testVectors(testName+"row 1 inferMaxProd", makeCol((Real)0, 1, (Real)0, (Real)0), output);

    // Row 2 matches only row 2 and half row 3
    table.inferRow (rows[2], output, CondProbTable::inferMaxProd);
    testVectors(testName+"row 2 inferMaxProd", makeCol((Real)0, (Real)0, (Real).36, (Real).24), output);

    // Row 3 matches row 0 & row 2 halfway, and row 3 exactly
    table.inferRow (rows[3], output, CondProbTable::inferMaxProd);
    testVectors(testName+"row 3 inferMaxProd", makeCol((Real).24, (Real)0, (Real).24, (Real).36), output);
  
  
    // --------------------------------------------------------------------
    // Try out inferViterbi inference
  
    // Row 0 matches row 0 and half row 3, so we get half and half hits on those rows
    table.inferRow (rows[0], output, CondProbTable::inferViterbi);
    testVectors(testName+"row 0 inferViterbi", makeCol((Real)0, (Real)0, (Real)0, (Real).4), output);
  
    // Row 1 matches only row 1
    table.inferRow (rows[1], output, CondProbTable::inferViterbi);
    testVectors(testName+"row 1 inferViterbi", makeCol((Real)0, 1, (Real)0, (Real)0), output);

    // Row 2 matches only row 2 and half row 3
    table.inferRow (rows[2], output, CondProbTable::inferViterbi);
    testVectors(testName+"row 2 inferViterbi", makeCol((Real)0, (Real)0, (Real).6, (Real)0), output);

    // Row 3 matches row 0 & row 2 halfway, and row 3 exactly
    table.inferRow (rows[3], output, CondProbTable::inferViterbi);
    testVectors(testName+"row 3 inferViterbi", makeCol((Real)0, (Real)0, (Real).4, (Real).6), output);
  
  
    // Add a row a second time, the row should double in value
    table.updateRow(0, rows[0]);
    expValue = rows[0];
    for (Size i=0; i<numCols(); i++)
      expValue[i] *= 2;
    table.getRow(0, testRow);
    testVectors(testName+"row 0 update#2", expValue, testRow);
  
  }
Example #9
0
  void CollectionTest::testCollectionAddRemove()
  {
    Collection<int> c;
    c.add("0", 0);
    c.add("1", 1);
    c.add("2", 2);
    // c is now: 0,1,2
    TEST(c.contains("0"));
    TEST(c.contains("1"));
    TEST(c.contains("2"));
    TEST(!c.contains("3"));
      
    SHOULDFAIL(c.add("0", 0));
    SHOULDFAIL(c.add("1", 1));
    SHOULDFAIL(c.add("2", 2));

    TESTEQUAL(0, c.getByName("0"));
    TESTEQUAL(1, c.getByName("1"));
    TESTEQUAL(2, c.getByName("2"));

    TESTEQUAL(0, c.getByIndex(0).second);
    TESTEQUAL(1, c.getByIndex(1).second);
    TESTEQUAL(2, c.getByIndex(2).second);

    TEST(c.getCount() == 3);

    SHOULDFAIL(c.remove("4"));

    // remove in middle of collection
    c.remove("1");
    // c is now 0, 2
    SHOULDFAIL(c.remove("1"));
    
    TEST(c.getCount() == 2);
    TEST(c.contains("0"));
    TEST(!c.contains("1"));
    TEST(c.contains("2"));

    TESTEQUAL(0, c.getByIndex(0).second);
    // item "2" has shifted into position 1
    TESTEQUAL(2, c.getByIndex(1).second);
    
    // should append to end of collection
    c.add("1", 1);
    // c is now 0, 2, 1
    TEST(c.getCount() == 3);
    TEST(c.contains("1"));
    TESTEQUAL(0, c.getByIndex(0).second);
    TESTEQUAL(2, c.getByIndex(1).second);
    TESTEQUAL(1, c.getByIndex(2).second);

    SHOULDFAIL(c.add("0", 0));
    SHOULDFAIL(c.add("1", 1));
    SHOULDFAIL(c.add("2", 2));

    // remove at end of collection
    c.remove("1");
    // c is now 0, 2
    SHOULDFAIL(c.remove("1"));
    TEST(c.getCount() == 2);
    TESTEQUAL(0, c.getByIndex(0).second);
    TESTEQUAL(2, c.getByIndex(1).second);

    // continue removing until done
    c.remove("0");
    // c is now 2
    SHOULDFAIL(c.remove("0"));
    TEST(c.getCount() == 1);
    // "2" shifts to first position
    TESTEQUAL(2, c.getByIndex(0).second);

    c.remove("2");
    // c is now empty
    TEST(c.getCount() == 0);
    TEST(!c.contains("2"));

  }
Example #10
0
  void DimensionsTest::RunTests()
  {
    Coordinate zero; // [0];
    zero.push_back(0);

    Coordinate one_two; // [1,2]
    one_two.push_back(1);
    one_two.push_back(2);

    Coordinate three_four; // [3,4]
    three_four.push_back(3);
    three_four.push_back(4);
    

    {
      // empty dimensions (unspecified)
      Dimensions d;
      TEST(d.isUnspecified());
      TEST(d.isValid());
      TEST(!d.isDontcare());
      SHOULDFAIL(d.getCount());
      SHOULDFAIL(d.getDimension(0));
      TESTEQUAL("[unspecified]", d.toString());
      SHOULDFAIL(d.getIndex(one_two));
      SHOULDFAIL(d.getCount());
      SHOULDFAIL(d.getDimension(0));
      TESTEQUAL((unsigned int)0, d.getDimensionCount());
    }

    {
      // dontcare dimensions [0]
      Dimensions d;
      d.push_back(0);
      TEST(!d.isUnspecified());
      TEST(d.isDontcare());
      TEST(d.isValid());
      TESTEQUAL("[dontcare]", d.toString());
      SHOULDFAIL(d.getIndex(zero));
      SHOULDFAIL(d.getCount());
      TESTEQUAL((unsigned int)0, d.getDimension(0));
      TESTEQUAL((unsigned int)1, d.getDimensionCount());
    }


    {
      // invalid dimensions
      Dimensions d;
      d.push_back(1);
      d.push_back(0);
      TEST(!d.isUnspecified());
      TEST(!d.isDontcare());
      TEST(!d.isValid());
      TESTEQUAL("[1 0] (invalid)", d.toString());
      SHOULDFAIL(d.getIndex(one_two));
      SHOULDFAIL(d.getCount());
      TESTEQUAL((unsigned int)1, d.getDimension(0));
      TESTEQUAL((unsigned int)0, d.getDimension(1));
      SHOULDFAIL(d.getDimension(2));
      TESTEQUAL((unsigned int)2, d.getDimensionCount());
    }

    {
      // valid dimensions [2,3]
      // two rows, three columns
      Dimensions d;
      d.push_back(2);
      d.push_back(3);
      TEST(!d.isUnspecified());
      TEST(!d.isDontcare());
      TEST(d.isValid());
      TESTEQUAL("[2 3]", d.toString());
      TESTEQUAL((unsigned int)2, d.getDimension(0));
      TESTEQUAL((unsigned int)3, d.getDimension(1));
      SHOULDFAIL(d.getDimension(2));
      TESTEQUAL((unsigned int)6, d.getCount());
      TESTEQUAL((unsigned int)5, d.getIndex(one_two));
      TESTEQUAL((unsigned int)2, d.getDimensionCount());
    }

    {
      //check a two dimensional matrix for proper x-major ordering
      std::vector<size_t> x;
      x.push_back(4);
      x.push_back(5);
      Dimensions d(x);
      size_t testDim1 = 4;
      size_t testDim2 = 5;
      for(size_t i = 0; i < testDim1; i++)
      {
        for(size_t j = 0; j < testDim2; j++)
        {
          Coordinate testCoordinate;
          testCoordinate.push_back(i);
          testCoordinate.push_back(j);

          TESTEQUAL(i+j*testDim1, d.getIndex(testCoordinate));
          TESTEQUAL(vecToString(testCoordinate),
                    vecToString(d.getCoordinate(i+j*testDim1)));
        }
      }
    }

    {
      //check a three dimensional matrix for proper x-major ordering
      std::vector<size_t> x;
      x.push_back(3);
      x.push_back(4);
      x.push_back(5);
      Dimensions d(x);
      size_t testDim1 = 3;
      size_t testDim2 = 4;
      size_t testDim3 = 5;
      for(size_t i = 0; i < testDim1; i++)
      {
        for(size_t j = 0; j < testDim2; j++)
        {
          for(size_t k = 0; k < testDim3; k++)
          {
            Coordinate testCoordinate;
            testCoordinate.push_back(i);
            testCoordinate.push_back(j);
            testCoordinate.push_back(k);

            TESTEQUAL(i +
                      j*testDim1 +
                      k*testDim1*testDim2, d.getIndex(testCoordinate));

            TESTEQUAL(vecToString(testCoordinate),
                      vecToString(d.getCoordinate(i +
                                                  j*testDim1 +
                                                  k*testDim1*testDim2)));
          }
        }
      }
    }

    { 
      // alternate constructor
      std::vector<size_t> x;
      x.push_back(2);
      x.push_back(5);
      Dimensions d(x);
      TEST(!d.isUnspecified());
      TEST(!d.isDontcare());
      TEST(d.isValid());
      
      TESTEQUAL((unsigned int)2, d.getDimension(0));
      TESTEQUAL((unsigned int)5, d.getDimension(1));
      SHOULDFAIL(d.getDimension(2));
      TESTEQUAL((unsigned int)2, d.getDimensionCount());
    }

  } // RunTests()