void testRemoveNonEmptySubFolder() { { long const blocks = 2048; boost::filesystem::path testPath = buildImage(m_uniquePath, blocks); teasafe::TeaSafeFolder folder = createTestFolder(testPath, blocks); teasafe::TeaSafeFolder subFolder = folder.getTeaSafeFolder("folderA"); subFolder.addTeaSafeFile("subFileA"); subFolder.addTeaSafeFile("subFileB"); subFolder.addTeaSafeFile("subFileC"); subFolder.addTeaSafeFile("subFileD"); std::string testData("some test data!"); teasafe::TeaSafeFile entry = subFolder.getTeaSafeFile("subFileB", teasafe::OpenDisposition::buildAppendDisposition()); std::vector<uint8_t> vec(testData.begin(), testData.end()); entry.write((char*)&vec.front(), testData.length()); entry.flush(); } { long const blocks = 2048; boost::filesystem::path testPath = buildImage(m_uniquePath, blocks); teasafe::TeaSafeFolder folder = createTestFolder(testPath, blocks); folder.removeTeaSafeFolder("folderA"); std::vector<teasafe::EntryInfo> entries = folder.listAllEntries(); ASSERT_EQUAL(entries.size(), 5, "testRemoveNonEmptySubFolder: number of entries after removal"); } }
TEST_F(KeymasterTest, SignData_RSA_Raw_InvalidSizeInput_Failure) { uint8_t* key_blob; size_t key_blob_length; UniqueReadOnlyBlob testKey(TEST_SIGN_RSA_KEY_1, sizeof(TEST_SIGN_RSA_KEY_1)); ASSERT_TRUE(testKey.get() != NULL); ASSERT_EQ(0, sDevice->import_keypair(sDevice, testKey.get(), testKey.length(), &key_blob, &key_blob_length)) << "Should successfully import an RSA key"; UniqueKey key(&sDevice, key_blob, key_blob_length); keymaster_rsa_sign_params_t params = { .digest_type = DIGEST_NONE, .padding_type = PADDING_NONE, }; uint8_t* sig; size_t sig_length; UniqueReadOnlyBlob testData(TEST_RSA_KEY_1, sizeof(TEST_RSA_KEY_1)); ASSERT_TRUE(testData.get() != NULL); ASSERT_EQ(-1, sDevice->sign_data(sDevice, ¶ms, key_blob, key_blob_length, testData.get(), testData.length(), &sig, &sig_length)) << "Should not be able to do raw signature on incorrect size data"; }
int CommonBigNum(int argc, char *const *argv) { plan_tests(kTestTestCount); for(int i=0; i<10; i++) { testCreateFree(); testHexString(); testData(); testI(); testCompare(); testBitCount(); testAddSub(); testAddSubI(); testShift(); testMod(); testModI(); testModExp(); testMul(); testMulI(); testPrime(); testDiv(); testMulMod(); } return 0; }
void testEntryRetrievalAppendLargeToFirstFileAndAppendSmallToSecond() { long const blocks = 2048; boost::filesystem::path testPath = buildImage(m_uniquePath, blocks); teasafe::TeaSafeFolder folder = createTestFolder(testPath, blocks); { std::string testString(createLargeStringToWrite()); teasafe::TeaSafeFile entry = folder.getTeaSafeFile("picture.jpg", teasafe::OpenDisposition::buildAppendDisposition()); std::vector<uint8_t> vec(testString.begin(), testString.end()); entry.write((char*)&vec.front(), testString.length()); entry.flush(); entry.seek(0); // seek to start since retrieving from folder automatically seeks to end vec.resize(entry.fileSize()); entry.read((char*)&vec.front(), entry.fileSize()); std::string result(vec.begin(), vec.end()); } { std::string testData("some test data!"); teasafe::TeaSafeFile entry = folder.getTeaSafeFile("some.log", teasafe::OpenDisposition::buildAppendDisposition()); std::vector<uint8_t> vec(testData.begin(), testData.end()); entry.write((char*)&vec.front(), testData.length()); entry.flush(); entry.seek(0); // seek to start since retrieving from folder automatically seeks to end vec.resize(entry.fileSize()); entry.read((char*)&vec.front(), entry.fileSize()); std::string result(vec.begin(), vec.end()); ASSERT_EQUAL(result, testData, "testEntryRetrievalAppendLargeToFirstFileAndAppendSmallToSecond"); } }
/** @test the table of test frames * computed on demand */ void useFrameTable() { TestFrame& frX = testData(3,50); TestFrame& frY = testData(3,25); TestFrame& frZ = testData(3,50); CHECK (frX.isSane()); CHECK (frY.isSane()); CHECK (frZ.isSane()); CHECK (frX != frY); CHECK (frX == frZ); CHECK (frY != frZ); CHECK (isSameObject (frX, frZ)); corruptMemory(&frZ,40,20); CHECK (!frX.isSane()); CHECK (!testData(3,50).isSane()); CHECK ( testData(3,51).isSane()); CHECK ( testData(3,49).isSane()); resetTestFrames(); CHECK ( testData(3,50).isSane()); }
void Engine::PassRenderData() { std::vector<GLchar> testData(OCT.CompositeResults.begin(), OCT.CompositeResults.begin() + ((500 * 512 * 4)) * RenderLayerCount); EngineRenderer.InitializeRenderData(testData,RenderLayerCount); enableRendering = true; }
void MCMeshLoaderTest::testSimple() { QString testData(TEST_DATA_CUBE); QTextStream testStream(&testData); m_dut.readStream(testStream); QVERIFY(m_dut.vertices().size() == 8); QVERIFY(m_dut.textureCoords().size() == 36); QVERIFY(m_dut.normals().size() == 36); }
static void TestFlate(skiatest::Reporter* reporter, SkMemoryStream* testStream, size_t dataSize) { if (testStream == NULL) return; SkMemoryStream testData(dataSize); uint8_t* data = (uint8_t*)testData.getMemoryBase(); srand(0); // Make data deterministic. for (size_t i = 0; i < dataSize; i++) data[i] = rand() & 0xFF; testStream->setMemory(testData.getMemoryBase(), dataSize, true); SkDynamicMemoryWStream compressed; bool status = SkFlate::Deflate(testStream, &compressed); REPORTER_ASSERT(reporter, status); // Check that the input data wasn't changed. size_t inputSize = testStream->getLength(); if (inputSize == 0) inputSize = testStream->read(NULL, SkZeroSizeMemStream::kGetSizeKey); REPORTER_ASSERT(reporter, testData.getLength() == inputSize); REPORTER_ASSERT(reporter, memcmp(testData.getMemoryBase(), testStream->getMemoryBase(), testData.getLength()) == 0); // Assume there are two test sizes, big and small. if (dataSize < 1024) REPORTER_ASSERT(reporter, compressed.getOffset() < 1024); else REPORTER_ASSERT(reporter, compressed.getOffset() > 1024); SkAutoDataUnref data1(compressed.copyToData()); testStream->setData(data1.get())->unref(); SkDynamicMemoryWStream uncompressed; status = SkFlate::Inflate(testStream, &uncompressed); REPORTER_ASSERT(reporter, status); // Check that the input data wasn't changed. inputSize = testStream->getLength(); if (inputSize == 0) inputSize = testStream->read(NULL, SkZeroSizeMemStream::kGetSizeKey); REPORTER_ASSERT(reporter, data1->size() == inputSize); REPORTER_ASSERT(reporter, memcmp(testStream->getMemoryBase(), data1->data(), data1->size()) == 0); // Check that the uncompressed data matches the source data. SkAutoDataUnref data2(uncompressed.copyToData()); REPORTER_ASSERT(reporter, testData.getLength() == uncompressed.getOffset()); REPORTER_ASSERT(reporter, memcmp(testData.getMemoryBase(), data2->data(), testData.getLength()) == 0); }
void testBasics(){ runTest(testInt()); runTest(testBool()); runTest(testString()); runTest(testData()); runTest(testBigdata()); runTest(testRange()); runTest(testLambda()); runTest(testSoft()); runTest(testPhantom()); runTest(testWeak()); }
void VisualMusicModelTest::testScoreDataChanged() { QString testData("Test title"); TestInteractingItem testInteractingItem; QModelIndex scoreIndex = m_musicModel->insertScore(0, "Test score"); VisualItem *visualItem = m_visualMusicModel->visualItemFromIndex(scoreIndex); Q_ASSERT(visualItem); visualItem->setGraphicalType(VisualItem::GraphicalInlineType); visualItem->setInlineGraphic(&testInteractingItem); QSignalSpy interactingItemSpy(&testInteractingItem, SIGNAL(setDataCalled())); m_musicModel->setData(scoreIndex, testData, LP::ScoreTitle); QVERIFY2(interactingItemSpy.count() == 1, "Data changed wasn't called on interacting graphics item"); }
TEST(SharedBufferReaderTest, clearSharedBufferBetweenCallsToReadData) { std::vector<char> testData(128); std::generate(testData.begin(), testData.end(), &std::rand); RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(&testData[0], testData.size()); SharedBufferReader reader(sharedBuffer); std::vector<char> destinationVector(testData.size()); const int bytesToRead = testData.size() / 2; EXPECT_EQ(bytesToRead, reader.readData(&destinationVector[0], bytesToRead)); sharedBuffer->clear(); EXPECT_EQ(0, reader.readData(&destinationVector[0], bytesToRead)); }
TEST_F(KeymasterTest, SignData_EC_Success) { uint8_t* key_blob; size_t key_blob_length; UniqueReadOnlyBlob testKey(TEST_SIGN_EC_KEY_1, sizeof(TEST_SIGN_EC_KEY_1)); ASSERT_TRUE(testKey.get() != NULL); ASSERT_EQ(0, sDevice->import_keypair(sDevice, testKey.get(), testKey.length(), &key_blob, &key_blob_length)) << "Should successfully import an EC key"; UniqueKey key(&sDevice, key_blob, key_blob_length); keymaster_ec_sign_params_t params = { .digest_type = DIGEST_NONE, }; uint8_t* sig; size_t sig_length; UniqueReadOnlyBlob testData(TEST_SIGN_DATA_1, sizeof(TEST_SIGN_DATA_1)); ASSERT_TRUE(testData.get() != NULL); ASSERT_EQ(0, sDevice->sign_data(sDevice, ¶ms, key_blob, key_blob_length, testData.get(), testData.length(), &sig, &sig_length)) << "Should sign data successfully"; UniqueBlob sig_blob(sig, sig_length); uint8_t* x509_data; size_t x509_data_length; ASSERT_EQ(0, sDevice->get_keypair_public(sDevice, key_blob, key_blob_length, &x509_data, &x509_data_length)) << "Should be able to retrieve RSA public key successfully"; UniqueBlob x509_blob(x509_data, x509_data_length); const unsigned char *tmp = static_cast<const unsigned char*>(x509_blob.get()); Unique_EVP_PKEY expected(d2i_PUBKEY((EVP_PKEY**) NULL, &tmp, static_cast<long>(x509_blob.length()))); Unique_EC_KEY ecKey(EVP_PKEY_get1_EC_KEY(expected.get())); ASSERT_EQ(1, ECDSA_verify(0, testData.get(), testData.length(), sig_blob.get(), sig_blob.length(), ecKey.get())) << "Signature should verify"; }
TEST(SharedBufferTest, copy) { Vector<char> testData(10000); std::generate(testData.begin(), testData.end(), &std::rand); size_t length = testData.size(); RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(testData.data(), length); sharedBuffer->append(testData.data(), length); sharedBuffer->append(testData.data(), length); sharedBuffer->append(testData.data(), length); // sharedBuffer must contain data more than segmentSize (= 0x1000) to check // copy(). ASSERT_EQ(length * 4, sharedBuffer->size()); RefPtr<SharedBuffer> clone = sharedBuffer->copy(); ASSERT_EQ(length * 4, clone->size()); ASSERT_EQ(0, memcmp(clone->data(), sharedBuffer->data(), clone->size())); clone->append(testData.data(), length); ASSERT_EQ(length * 5, clone->size()); }
TEST(SharedBufferReaderTest, readDataInMultiples) { const int iterationsCount = 8; const int bytesPerIteration = 64; std::vector<char> testData(iterationsCount * bytesPerIteration); std::generate(testData.begin(), testData.end(), &std::rand); RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(&testData[0], testData.size()); SharedBufferReader reader(sharedBuffer); std::vector<char> destinationVector(testData.size()); for (int i = 0; i < iterationsCount; ++i) { const int offset = i * bytesPerIteration; const int bytesRead = reader.readData(&destinationVector[0] + offset, bytesPerIteration); EXPECT_EQ(bytesPerIteration, bytesRead); } EXPECT_TRUE(std::equal(testData.begin(), testData.end(), destinationVector.begin())); }
void runTests() { // //testEncryption(); // testRandom(); // testSQL(); // testKeyStorage(); testHash(); testEncryption(); // testSQL(); testData(); // log("Test: %d", 54); // log("Test: %d", 53); // json_error_t error; // json_t *root = json_loads("aaa", 0, &error); // CURL *curl; // CURLcode res; // curl = curl_easy_init(); // if(curl) { // curl_easy_setopt(curl, CURLOPT_URL, "http://4enjoy.com"); // /* example.com is redirected, so we tell libcurl to follow redirection */ // curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); // /* Perform the request, res will get the return code */ // res = curl_easy_perform(curl); // /* Check for errors */ // if(res == CURLE_OK) // { // //std::cout << res; // } // //std::cout << res; // /* always cleanup */ // curl_easy_cleanup(curl); // } }
void testTeaSafeFolderRetrievalAddEntriesAppendData() { long const blocks = 2048; boost::filesystem::path testPath = buildImage(m_uniquePath, blocks); teasafe::TeaSafeFolder folder = createTestFolder(testPath, blocks); teasafe::TeaSafeFolder subFolder = folder.getTeaSafeFolder("folderA"); subFolder.addTeaSafeFile("subFileA"); subFolder.addTeaSafeFile("subFileB"); subFolder.addTeaSafeFile("subFileC"); subFolder.addTeaSafeFile("subFileD"); std::string testData("some test data!"); teasafe::TeaSafeFile entry = subFolder.getTeaSafeFile("subFileB", teasafe::OpenDisposition::buildAppendDisposition()); std::vector<uint8_t> vec(testData.begin(), testData.end()); entry.write((char*)&vec.front(), testData.length()); entry.flush(); entry.seek(0); // seek to start since retrieving from folder automatically seeks to end vec.resize(entry.fileSize()); entry.read((char*)&vec.front(), entry.fileSize()); std::string result(vec.begin(), vec.end()); ASSERT_EQUAL(result, testData, "testTeaSafeFolderRetrievalAddEntriesAppendData"); }
TEST_F(KeymasterTest, SignData_RSA_Raw_Success) { uint8_t* key_blob; size_t key_blob_length; UniqueReadOnlyBlob testKey(TEST_SIGN_RSA_KEY_1, sizeof(TEST_SIGN_RSA_KEY_1)); ASSERT_TRUE(testKey.get() != NULL); ASSERT_EQ(0, sDevice->import_keypair(sDevice, testKey.get(), testKey.length(), &key_blob, &key_blob_length)) << "Should successfully import an RSA key"; UniqueKey key(&sDevice, key_blob, key_blob_length); keymaster_rsa_sign_params_t params = { .digest_type = DIGEST_NONE, .padding_type = PADDING_NONE, }; uint8_t* sig; size_t sig_length; UniqueReadOnlyBlob testData(TEST_SIGN_DATA_1, sizeof(TEST_SIGN_DATA_1)); ASSERT_TRUE(testData.get() != NULL); ASSERT_EQ(0, sDevice->sign_data(sDevice, ¶ms, key_blob, key_blob_length, testData.get(), testData.length(), &sig, &sig_length)) << "Should sign data successfully"; UniqueBlob sig_blob(sig, sig_length); UniqueBlob expected_sig(TEST_SIGN_RSA_SIGNATURE_1, sizeof(TEST_SIGN_RSA_SIGNATURE_1)); ASSERT_EQ(expected_sig, sig_blob) << "Generated signature should match expected signature"; // The expected signature is actually stack data, so don't let it try to free. uint8_t* unused __attribute__((unused)) = expected_sig.release(); }
void UrlResolverTest::checkStoreAuthorizedKeys(){ QVERIFY(QDir().mkpath(Sandbox::map(QDir::homePath()))); QByteArray testData("# test data\n"); ssu.storeAuthorizedKeys(testData); QFile authorizedKeys(Sandbox::map(QDir::home().filePath(".ssh/authorized_keys"))); QVERIFY(authorizedKeys.open(QIODevice::ReadOnly)); QVERIFY(authorizedKeys.readAll().split('\n').contains(testData.trimmed())); QByteArray testData2("# test data2\n"); ssu.storeAuthorizedKeys(testData2); QEXPECT_FAIL("", "Ssu::storeAuthorizedKeys() does not modify existing authorized_keys", Continue); authorizedKeys.seek(0); QVERIFY(authorizedKeys.readAll().split('\n').contains(testData2.trimmed())); const QFile::Permissions go_rwx = QFile::ReadGroup | QFile::WriteGroup | QFile::ExeGroup | QFile::ReadOther | QFile::WriteOther | QFile::ExeOther; QVERIFY((QFileInfo(Sandbox::map(QDir::home().filePath(".ssh"))).permissions() & go_rwx) == 0); }
void MCMeshLoaderTest::testFace() { QString testData(TEST_DATA_CUBE); QTextStream testStream(&testData); m_dut.readStream(testStream); QVERIFY(m_dut.faces().size() == 12); MCMesh::Face face0 = m_dut.faces().at(0); QVERIFY(face0.vertices.size() == 3); QVERIFY(qFuzzyCompare(face0.vertices.at(0).x, -0.5f)); QVERIFY(qFuzzyCompare(face0.vertices.at(0).y, -0.5f)); QVERIFY(qFuzzyCompare(face0.vertices.at(0).z, 0.5f)); QVERIFY(qFuzzyCompare(face0.vertices.at(0).u, 1.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(0).v, 0.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(0).i, 0.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(0).j, 0.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(0).k, 1.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(1).x, 0.5f)); QVERIFY(qFuzzyCompare(face0.vertices.at(1).y, -0.5f)); QVERIFY(qFuzzyCompare(face0.vertices.at(1).z, 0.5f)); QVERIFY(qFuzzyCompare(face0.vertices.at(1).u, 0.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(1).v, 0.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(1).i, 0.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(1).j, 0.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(1).k, 1.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(2).x, -0.5f)); QVERIFY(qFuzzyCompare(face0.vertices.at(2).y, 0.5f)); QVERIFY(qFuzzyCompare(face0.vertices.at(2).z, 0.5f)); QVERIFY(qFuzzyCompare(face0.vertices.at(2).u, 0.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(2).v, 1.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(2).i, 0.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(2).j, 0.0f)); QVERIFY(qFuzzyCompare(face0.vertices.at(2).k, 1.0f)); MCMesh::Face face11 = m_dut.faces().at(11); QVERIFY(face11.vertices.size() == 3); QVERIFY(qFuzzyCompare(face11.vertices.at(0).x, 0.5f)); QVERIFY(qFuzzyCompare(face11.vertices.at(0).y, -0.5f)); QVERIFY(qFuzzyCompare(face11.vertices.at(0).z, 0.5f)); QVERIFY(qFuzzyCompare(face11.vertices.at(0).u, 0.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(0).v, 1.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(0).i, 0.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(0).j, -1.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(0).k, 0.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(1).x, -0.5f)); QVERIFY(qFuzzyCompare(face11.vertices.at(1).y, -0.5f)); QVERIFY(qFuzzyCompare(face11.vertices.at(1).z, 0.5f)); QVERIFY(qFuzzyCompare(face11.vertices.at(1).u, 0.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(1).v, 0.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(1).i, 0.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(1).j, -1.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(1).k, 0.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(2).x, -0.5f)); QVERIFY(qFuzzyCompare(face11.vertices.at(2).y, -0.5f)); QVERIFY(qFuzzyCompare(face11.vertices.at(2).z, -0.5f)); QVERIFY(qFuzzyCompare(face11.vertices.at(2).u, 1.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(2).v, 0.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(2).i, 0.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(2).j, -1.0f)); QVERIFY(qFuzzyCompare(face11.vertices.at(2).k, 0.0f)); }
int Praat_tests (int itest, char32 *arg1, char32 *arg2, char32 *arg3, char32 *arg4) { int64 n = Melder_atoi (arg1); double t = 0.0; (void) arg1; (void) arg2; (void) arg3; (void) arg4; Melder_clearInfo (); Melder_stopwatch (); switch (itest) { case kPraatTests_TIME_RANDOM_FRACTION: { for (int64 i = 1; i <= n; i ++) (void) NUMrandomFraction (); t = Melder_stopwatch (); } break; case kPraatTests_TIME_RANDOM_GAUSS: { for (int64 i = 1; i <= n; i ++) (void) NUMrandomGauss (0.0, 1.0); t = Melder_stopwatch (); } break; case kPraatTests_TIME_SORT: { long m = Melder_atoi (arg2); long *array = NUMvector <long> (1, m); for (int64 i = 1; i <= m; i ++) array [i] = NUMrandomInteger (1, 100); Melder_stopwatch (); for (int64 i = 1; i <= n; i ++) NUMsort_l (m, array); t = Melder_stopwatch (); NUMvector_free (array, 1); } break; case kPraatTests_TIME_INTEGER: { int64 sum = 0; for (int64 i = 1; i <= n; i ++) sum += i * (i - 1) * (i - 2); t = Melder_stopwatch (); MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_FLOAT: { double sum = 0.0, fn = n; for (double fi = 1.0; fi <= fn; fi = fi + 1.0) sum += fi * (fi - 1.0) * (fi - 2.0); t = Melder_stopwatch (); MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_FLOAT_TO_UNSIGNED_BUILTIN: { uint64_t sum = 0; double fn = n; for (double fi = 1.0; fi <= fn; fi = fi + 1.0) sum += (uint32) fi; t = Melder_stopwatch (); // 2.59 // 1.60 MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_FLOAT_TO_UNSIGNED_EXTERN: { uint64_t sum = 0; double fn = n; for (double fi = 1.0; fi <= fn; fi = fi + 1.0) sum += (uint32) ((int32) (fi - 2147483648.0) + 2147483647L + 1); t = Melder_stopwatch (); // 1.60 MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_UNSIGNED_TO_FLOAT_BUILTIN: { double sum = 0.0; uint32 nu = (uint32) n; for (uint32 iu = 1; iu <= nu; iu ++) sum += (double) iu; t = Melder_stopwatch (); // 1.35 MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_UNSIGNED_TO_FLOAT_EXTERN: { double sum = 0.0; uint32 nu = (uint32) n; for (uint32 iu = 1; iu <= nu; iu ++) sum += (double) (int32) (iu - 2147483647L - 1) + 2147483648.0; t = Melder_stopwatch (); // 0.96 MelderInfo_writeLine (sum); } break; case kPraatTests_TIME_STRING_MELDER_32: { autoMelderString string; char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { MelderString_copy (& string, word); for (int j = 1; j <= 30; j ++) MelderString_append (& string, word); } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_MELDER_32_ALLOC: { char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { autoMelderString string; MelderString_copy (& string, word); for (int j = 1; j <= 30; j ++) MelderString_append (& string, word); } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_S: { std::string s = ""; char word [] { "abc" }; word [2] = (char) NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_C: { std::basic_string<char> s = ""; char word [] { "abc" }; word [2] = (char) NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_WS: { std::wstring s = L""; wchar_t word [] { L"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_WC: { std::basic_string<wchar_t> s = L""; wchar_t word [] { L"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_32: { std::basic_string<char32_t> s = U""; char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRING_CPP_U32STRING: { std::u32string s = U""; char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { s = word; for (int j = 1; j <= 30; j ++) s += word; } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STRCPY: { char buffer [100]; char word [] { "abc" }; word [2] = (char) NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { strcpy (buffer, word); for (int j = 1; j <= 30; j ++) strcpy (buffer + strlen (buffer), word); } t = Melder_stopwatch (); MelderInfo_writeLine (Melder_peek8to32 (buffer)); } break; case kPraatTests_TIME_WCSCPY: { wchar_t buffer [100]; wchar_t word [] { L"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { wcscpy (buffer, word); for (int j = 1; j <= 30; j ++) wcscpy (buffer + wcslen (buffer), word); } t = Melder_stopwatch (); } break; case kPraatTests_TIME_STR32CPY: { char32 buffer [100]; char32 word [] { U"abc" }; word [2] = NUMrandomInteger ('a', 'z'); for (int64 i = 1; i <= n; i ++) { str32cpy (buffer, word); for (int j = 1; j <= 30; j ++) str32cpy (buffer + str32len (buffer), word); } t = Melder_stopwatch (); MelderInfo_writeLine (buffer); } break; case kPraatTests_TIME_GRAPHICS_TEXT_TOP: { autoPraatPicture picture; for (int64 i = 1; i <= n; i ++) { Graphics_textTop (GRAPHICS, false, U"hello world"); } t = Melder_stopwatch (); } break; case kPraatTests_THING_AUTO: { int numberOfThingsBefore = theTotalNumberOfThings; { Melder_casual (U"1\n"); autoDaata data = Thing_new (Daata); Thing_setName (data.get(), U"hello"); Melder_casual (U"2\n"); testData (data.get()); testAutoData (data.move()); autoDaata data18 = Thing_new (Daata); testAutoData (data18.move()); fprintf (stderr, "3\n"); autoDaata data2 = newAutoData (); fprintf (stderr, "4\n"); autoDaata data3 = newAutoData (); fprintf (stderr, "5\n"); //data2 = data; // disabled l-value copy assignment from same class fprintf (stderr, "6\n"); autoOrdered ordered = Thing_new (Ordered); fprintf (stderr, "7\n"); //data = ordered; // disabled l-value copy assignment from subclass data = ordered.move(); //ordered = data; // disabled l-value copy assignment from superclass //ordered = data.move(); // assignment from superclass to subclass is rightfully refused by compiler fprintf (stderr, "8\n"); data2 = newAutoData (); fprintf (stderr, "8a\n"); autoDaata data5 = newAutoData (); fprintf (stderr, "8b\n"); data2 = data5.move(); fprintf (stderr, "9\n"); //ordered = data; // rightfully refused by compiler fprintf (stderr, "10\n"); //autoOrdered ordered2 = Thing_new (Daata); // rightfully refused by compiler fprintf (stderr, "11\n"); autoDaata data4 = Thing_new (Ordered); // constructor fprintf (stderr, "12\n"); //autoDaata data6 = data4; // disabled l-value copy constructor from same class fprintf (stderr, "13\n"); autoDaata data7 = data4.move(); fprintf (stderr, "14\n"); autoOrdered ordered3 = Thing_new (Ordered); autoDaata data8 = ordered3.move(); fprintf (stderr, "15\n"); //autoDaata data9 = ordered; // disabled l-value copy constructor from subclass fprintf (stderr, "16\n"); autoDaata data10 = data7.move(); fprintf (stderr, "17\n"); autoDaata data11 = Thing_new (Daata); // constructor, move assignment, null destructor fprintf (stderr, "18\n"); data11 = Thing_new (Ordered); fprintf (stderr, "19\n"); testAutoDataRef (data11); fprintf (stderr, "20\n"); //data11 = nullptr; // disabled implicit assignment of pointer to autopointer fprintf (stderr, "21\n"); } int numberOfThingsAfter = theTotalNumberOfThings; fprintf (stderr, "Number of things: before %d, after %d\n", numberOfThingsBefore, numberOfThingsAfter); #if 1 MelderCallback<void,structDaata>::FunctionType f; typedef void (*DataFunc) (Daata); typedef void (*OrderedFunc) (Ordered); DataFunc dataFun; OrderedFunc orderedFun; MelderCallback<void,structDaata> dataFun2 (dataFun); MelderCallback<void,structOrdered> orderedFun2 (orderedFun); MelderCallback<void,structDaata> dataFun3 (orderedFun); //MelderCallback<void,structOrdered> orderedFun3 (dataFun); // rightfully refused by compiler autoDaata data = Thing_new (Daata); dataFun3 (data.get()); #endif } break; } MelderInfo_writeLine (Melder_single (t / n * 1e9), U" nanoseconds"); MelderInfo_close (); return 1; }
int main() { // init variables double error = 0.; int truecnt = 0; int times,timed; // print useful info for reference std::cout << "\n" << "hidden neurons: " << "\t \t" << HIDDEN << std::endl; // init random number generator srand((int)time(NULL)); // create network std::cout << "initializing network..." << "\t \t"; NeuralNet DigitNet; NeuralLayer * pHiddenLayer1 = new NeuralTanhLayer(INPUT,HIDDEN); DigitNet.addLayer( pHiddenLayer1 ); NeuralLayer * pOutputLayer = new NeuralSoftmaxLayer(HIDDEN,OUTPUT); DigitNet.addLayer( pOutputLayer ); // set output type: // SCALAR = tanh or sigmoid output layer (use one output neuron) // PROB = softmax output layer, 1-of-N output encoding (use two output neurons) const unsigned int outType = PROB; // set learning rate, momentum, decay rate const double learningRate = 0.15; const double momentum = 0.0; const double decayRate = 0.0; DigitNet.setParams(learningRate,momentum,decayRate,outType); std::cout << "done" << std::endl; // load training and test data std::cout << "loading data..." << "\t \t \t"; std::vector< std::vector<double> > bigData( DATA_SIZE,std::vector<double>(INPUT+1,0.0) ); loadFromFile(bigData,"train.txt"); std::vector< std::vector<double> > trainData( TRAIN_SIZE,std::vector<double>(INPUT+1,0.0) ); std::vector< std::vector<double> > testData( TEST_SIZE,std::vector<double>(INPUT+1,0.0) ); buildData(bigData,trainData,TRAIN_SIZE,testData,TEST_SIZE); std::cout << "done" << std::endl; // loop over training data points and train net // slice off first column of each row (example) times=(int)time(NULL); // init time counter std::cout << "\n" << "training examples: " << "\t \t" << TRAIN_SIZE << std::endl; std::cout << "learning rate: " << "\t \t \t" << learningRate << std::endl; std::cout << "momentum: " << "\t \t \t" << momentum << std::endl; std::cout << "weight decay: " << "\t \t \t" << decayRate << std::endl; std::cout << "training network..." << "\t \t"; for(int i=0;i<TRAIN_SIZE;++i) { std::vector<double> data = trainData[i]; // extract data point double label = data[0]; // extract point label data.erase(data.begin()); std::vector<double> nLabel = encode((int)label); // encode to 1-of-N std::vector<double> outputs = DigitNet.runNet(data); error = DigitNet.trainNet(data,nLabel,outType); // train net, return MSE // decode output and compare to correct output if( decode(outputs) == (int)label ) truecnt++; } // stop timer and print out useful info timed=(int)time(NULL); times=timed-times; std::cout << "done" << std::endl; std::cout << "training time: " << "\t \t \t" << times << " seconds " << std::endl; std::cout << "training accuracy: " << "\t \t" << truecnt*100./TRAIN_SIZE << "%" << std::endl; // test net on test data times=(int)time(NULL); // init time counter std::cout << "\n" << "test points: " << "\t \t \t" << TEST_SIZE << std::endl; std::cout << "testing network..." << "\t \t"; truecnt = 0; for(int i=0;i<TEST_SIZE;++i) { std::vector<double> data = testData[i]; // extract data point double label = data[0]; // extract label data.erase(data.begin()); std::vector<double> outputs = DigitNet.runNet(data); // run net // decode output and compare to correct output if( decode(outputs) == (int)label ) truecnt++; } // stop timer and print out useful info timed=(int)time(NULL); times=timed-times; std::cout << "done" << std::endl; std::cout << "testing time: " << "\t \t \t" << times << " seconds " << std::endl; std::cout << "test accuracy: " << "\t \t \t" << truecnt*100./TEST_SIZE << "% " << std::endl; // save weights to reuse net in the future DigitNet.saveNet(); }
static void TestFlate(skiatest::Reporter* reporter, SkMemoryStream* testStream, size_t dataSize) { SkASSERT(testStream != NULL); SkAutoDataUnref testData(new_test_data(dataSize)); SkASSERT(testData->size() == dataSize); testStream->setMemory(testData->data(), dataSize, /*copyData=*/ true); SkDynamicMemoryWStream compressed; bool deflateSuccess = SkFlate::Deflate(testStream, &compressed); REPORTER_ASSERT(reporter, deflateSuccess); // Check that the input data wasn't changed. size_t inputSize = testStream->getLength(); if (inputSize == 0) { inputSize = testStream->read(NULL, SkZeroSizeMemStream::kGetSizeKey); } REPORTER_ASSERT(reporter, dataSize == inputSize); if (dataSize == inputSize) { REPORTER_ASSERT(reporter, memcmp(testData->data(), testStream->getMemoryBase(), dataSize) == 0); } size_t compressedSize = compressed.getOffset(); SkAutoDataUnref compressedData(compressed.copyToData()); testStream->setData(compressedData.get()); SkDynamicMemoryWStream uncompressed; bool inflateSuccess = SkFlate::Inflate(testStream, &uncompressed); REPORTER_ASSERT(reporter, inflateSuccess); // Check that the input data wasn't changed. inputSize = testStream->getLength(); if (inputSize == 0) { inputSize = testStream->read(NULL, SkZeroSizeMemStream::kGetSizeKey); } REPORTER_ASSERT(reporter, compressedSize == inputSize); if (compressedData->size() == inputSize) { REPORTER_ASSERT(reporter, memcmp(testStream->getMemoryBase(), compressedData->data(), compressedData->size()) == 0); } // Check that the uncompressed data matches the source data. SkAutoDataUnref uncompressedData(uncompressed.copyToData()); REPORTER_ASSERT(reporter, dataSize == uncompressedData->size()); if (dataSize == uncompressedData->size()) { REPORTER_ASSERT(reporter, memcmp(testData->data(), uncompressedData->data(), dataSize) == 0); } if (compressedSize < 1) { return; } double compressionRatio = static_cast<double>(dataSize) / compressedSize; // Assert that some compression took place. REPORTER_ASSERT(reporter, compressionRatio > 1.2); if (reporter->verbose()) { SkDebugf("Flate Test: \t input size: " SK_SIZE_T_SPECIFIER "\tcompressed size: " SK_SIZE_T_SPECIFIER "\tratio: %.4g\n", dataSize, compressedSize, compressionRatio); } }
bool ANBC_Model::train(UINT classLabel,MatrixDouble &trainingData,VectorDouble &weightsVector){ //Check to make sure the column sizes match if( trainingData.getNumCols() != weightsVector.size() ){ N = 0; return false; } UINT M = trainingData.getNumRows(); N = trainingData.getNumCols(); this->classLabel = classLabel; //Update the weights buffer weights = weightsVector; //Resize the buffers mu.resize( N ); sigma.resize( N ); //Calculate the mean for each dimension for(UINT j=0; j<N; j++){ mu[j] = 0.0; for(UINT i=0; i<M; i++){ mu[j] += trainingData[i][j]; } mu[j] /= double(M); if( mu[j] == 0 ){ return false; } } //Calculate the sample standard deviation for(UINT j=0; j<N; j++){ sigma[j] = 0.0; for(UINT i=0; i<M; i++){ sigma[j] += SQR( trainingData[i][j]-mu[j] ); } sigma[j] = sqrt( sigma[j]/double(M-1) ); if( sigma[j] == 0 ){ return false; } } //Now compute the threshold double meanPrediction = 0.0; VectorDouble predictions(M); for(UINT i=0; i<M; i++){ //Test the ith training example vector<double> testData(N); for(UINT j=0; j<N; j++) { testData[j] = trainingData[i][j]; } predictions[i] = predict(testData); meanPrediction += predictions[i]; } //Calculate the mean prediction value meanPrediction /= double(M); //Calculate the standard deviation double stdDev = 0.0; for(UINT i=0; i<M; i++) { stdDev += SQR( predictions[i]-meanPrediction ); } stdDev = sqrt( stdDev / (double(M)-1.0) ); threshold = meanPrediction-(stdDev*gamma); //Update the training mu and sigma values so the threshold value can be dynamically computed at a later stage trainingMu = meanPrediction; trainingSigma = stdDev; return true; }
CubeMapTexture* CubeMapTexture::Load(int size) { CubeMapTexture* cubeMap = new CubeMapTexture(); Texture::SetActiveTextureUnit(0); cubeMap->Bind(); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0)); GL_C(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 0)); GL_C(glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS)); struct RGBA { GLubyte r; GLubyte g; GLubyte b; GLubyte a; }; RGBA green; green.r = 0;green.g = 255;green.b = 0;green.a = 255; RGBA red; red.r = 255;red.g = 0;red.b = 0;red.a = 255; std::vector<RGBA> testData(size * size * sizeof(RGBA), green ); std::vector<RGBA> xData(size * size * sizeof(RGBA), red); for(int i = 0; i < 6; ++i) { std::vector<RGBA> d = i % 2 == 0 ? testData : xData; glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, GL_RGBA8 , size,size, 0, GL_RGBA, GL_UNSIGNED_BYTE, /*&d[0]*/ nullptr); /* GL_C(glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE )); GL_C(glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE )); */ // GL_C(glGenerateMipmap(m_target)); } /* GL_C(glFinish() ); GL_C(glFlush() ); }*/ // cubeMap->SetTextureClamping(); // cubeMap->SetTextureWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); // cubeMap->GenerateMipmap(); // cubeMap->Unbind(); return cubeMap; }