glm::vec3 Camera::getEye() const { //Get Camera position (from: http://www.opengl.org/discussion_boards/showthread.php/178484-Extracting-camera-position-from-a-ModelView-Matrix ) glm::mat4 modelViewT = glm::transpose(m_view); // Get plane normals glm::vec3 n1(modelViewT[0]); glm::vec3 n2(modelViewT[1]); glm::vec3 n3(modelViewT[2]); // Get plane distances float d1(modelViewT[0].w); float d2(modelViewT[1].w); float d3(modelViewT[2].w); // Get the intersection of these 3 planes // (using math from RealTime Collision Detection by Christer Ericson) glm::vec3 n2n3 = glm::cross(n2, n3); float denom = glm::dot(n1, n2n3); glm::vec3 eye = (n2n3 * d1) + glm::cross(n1, (d3*n2) - (d2*n3)); eye /= -denom; return eye; }
int main(int argc, char const *argv[]) { ListNode n1(5); ListNode n2(10); ListNode n3(2); ListNode n4(3); n1.next = &n2; n2.next = &n3; n3.next = &n4; solve(&n1); ListNode* itr = &n1; while(itr) { std::cout << "At node with value " << itr->data << std::endl; std::cout << "Biggest in right: "; if(itr->arbitrary) std::cout << itr->arbitrary->data; else std::cout << "NULL"; std::cout << std::endl << std::endl; itr = itr->next; } return 0; }
int main(){ Node head1(3); Node n1(2); Node n2(1); Node n3(5); Node n4(6); head1.Left=&n1; head1.Right=&n3; n1.Left=&n2; n3.Right=&n4; Node head2(9); Node n1b(8); Node n2b(2); Node n3b(10); Node n4b(11); head2.Left=&n1b; head2.Right=&n3b; n1b.Left=&n2b; n3b.Right=&n4b; std::cout << " the median of the two arrays is : " << std::setprecision( 2 )<< arrayMedian(&head1,&head2)<<std::endl; return 0; }
int main() { TreeNode n1(5); TreeNode n2(4); TreeNode n3(8); TreeNode n4(11); TreeNode n5(13); TreeNode n6(4); TreeNode n7(7); TreeNode n8(2); TreeNode n9(1); n1.left = &n2; n1.right = &n3; n2.left = &n4; n4.left = &n7; n4.right = &n8; n3.left = &n5; n3.right = &n6; n6.right = &n9; Solution sln; cout << sln.hasPathSum(&n1, 22) << endl; return 0; }
main() { P1DIR = 0xFF; while(1) { n1(); delay(65000); n2(); delay(65000); n3(); delay(65000); n4(); delay(65000); n5(); delay(65000); n6(); delay(65000); n7(); delay(65000); n8(); delay(65000); n9(); delay(65000); n0(); delay(65000); } }
static void TestPDFDict(skiatest::Reporter* reporter) { SkAutoTUnref<SkPDFDict> dict(new SkPDFDict); ASSERT_EMIT_EQ(reporter, *dict, "<<>>"); dict->insertInt("n1", SkToSizeT(42)); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42>>"); dict.reset(new SkPDFDict); ASSERT_EMIT_EQ(reporter, *dict, "<<>>"); dict->insertInt("n1", 42); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42>>"); dict->insertScalar("n2", SK_ScalarHalf); SkString n3("n3"); SkAutoTUnref<SkPDFArray> innerArray(new SkPDFArray); innerArray->appendInt(-100); dict->insertObject(n3, innerArray.detach()); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42\n/n2 0.5\n/n3 [-100]>>"); dict.reset(new SkPDFDict); ASSERT_EMIT_EQ(reporter, *dict, "<<>>"); dict->insertInt("n1", 24); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24>>"); dict->insertInt("n2", SkToSizeT(99)); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99>>"); dict->insertScalar("n3", SK_ScalarHalf); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 0.5>>"); dict->insertName("n4", "AName"); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 0.5\n/n4 /AName>>"); dict->insertName("n5", SkString("AnotherName")); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 0.5\n/n4 /AName\n" "/n5 /AnotherName>>"); dict->insertString("n6", "A String"); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 0.5\n/n4 /AName\n" "/n5 /AnotherName\n/n6 (A String)>>"); dict->insertString("n7", SkString("Another String")); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 0.5\n/n4 /AName\n" "/n5 /AnotherName\n/n6 (A String)\n/n7 (Another String)>>"); dict.reset(new SkPDFDict("DType")); ASSERT_EMIT_EQ(reporter, *dict, "<</Type /DType>>"); SkAutoTUnref<SkPDFArray> referencedArray(new SkPDFArray); Catalog catalog; catalog.numbers.addObject(referencedArray.get()); REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber( referencedArray.get()) == 1); dict->insertObjRef("n1", referencedArray.detach()); SkString result = emit_to_string(*dict, &catalog); ASSERT_EQ(reporter, result, "<</Type /DType\n/n1 1 0 R>>"); }
TEST(KmerNodeTest, SimpleEquality) { KmerNode n1("ACGTTCTC", 23); KmerNode n2("ACGTTCTC", 441); KmerNode n3("TTCTCACAGAG", 352); EXPECT_EQ(n1,n2); EXPECT_NE(n1,n3); }
int main(int argc, char* argv[]) { Solution s; ListNode n1(1); ListNode n3(3); ListNode n5(5); ListNode n2(2); ListNode n4(4); ListNode n6(6); n1.next = &n3; n3.next = &n5; n2.next = &n4; n4.next = &n6; ListNode *ret1 = s.mergeTwoLists(&n1, &n2); int i = 0; while (ret1 != NULL) { i++; assert(ret1->val == i); ret1 = ret1->next; } i = 2; ret1 = s.mergeTwoLists(&n1, NULL); while (ret1 == NULL) { assert(ret1->val == 2); i += 2; ret1 = ret1->next; } return 0; }
END_TEST START_TEST(test_constructor) { numa_node nn; fail_unless(nn.get_total_cpus() == 0); fail_unless(nn.get_total_memory() == 0); fail_unless(nn.get_available_memory() == 0); fail_unless(nn.get_available_cpus() == 0); fail_unless(nn.get_my_index() == 0); // verify that this doesn't segfault nn.get_meminfo(NULL); nn.get_meminfo("/proc/meminfo"); fail_unless(nn.get_total_memory() == 1024 * 5); fail_unless(nn.get_available_memory() == nn.get_total_memory()); numa_node n2("../../../../test/test_files", 0); fail_unless(n2.get_total_memory() == 1024 * 5); fail_unless(n2.get_total_cpus() == 4); numa_node n3(n2); fail_unless(n3.get_total_memory() == 1024 * 5); fail_unless(n3.get_total_cpus() == 4); fail_unless(n3.get_available_cpus() == n2.get_available_cpus()); fail_unless(n3.get_available_memory() == n2.get_available_memory()); }
main(int argc, char *argv[]) { node gnd; node n1("n1"); node n2("n2"); node n3("n3"); node n4("n4"); node n5("n5"); node n6("n6"); vdc vcc("vcc", n6, gnd, 5.0); vpulse vin("vin", n1, gnd, 0, 5, 2e-9, 2e-9, 2e-9, 10e-9); r rb1("rb1", n1, n2, 10e3); r rc1("rc1", n6, n3, 1e3); qnd q1("q1", n3, n2, gnd); r rb2("rb2", n3, n4, 10e3); qnd q2("q2", n5, n4, gnd); r rc2("rc2", n6, n5, 1e3); op::monitor = 1; op(); plot::output = *argv; plot::add("n1", "n3", "n5"); tran::tsmin = 1.0e-30; tran::monitor = 1; tran(0.2e-9, 20.0e-9); }
void TestSortList() { SortList::ListNode node4(1); SortList::ListNode node3(2); node3.next = &node4; SortList::ListNode node2(3); node2.next = &node3; SortList::ListNode node1(4); node1.next = &node2; SortList::SolutionSortList so; SortList::ListNode *newhead = so.sortList(&node1); node4.next = &node2; node2.next = &node3; node3.next = nullptr; newhead = so.sortList(&node4);//1,3,2 SortList::ListNode n1(1); SortList::ListNode n2(2); n2.next = &n1; SortList::ListNode n3(3); n3.next = &n2; SortList::ListNode n4(4); n4.next = &n3; SortList::ListNode n5(5); n5.next = &n4; newhead = so.sortList(&n5); }
Real aneurismFluxInVectorial(const Real& t, const Real& x, const Real& y, const Real& z, const ID& i) { //Components for Simone's mesh /* Real n1(-0.000019768882940); Real n2(-0.978289616345544); Real n3( 0.207242433298975); */ /* Real n1(-0.67460); Real n2(-0.19888); Real n3(-0.17089); */ Real n1(-0.671731456); Real n2(-0.204172511); Real n3(-0.712102827); Real flux(fluxFunctionAneurysm(t,x,y,z,i)); //Simone's area //Real area(0.0907122); // Computed with the triangle on the INLET boundary //Real area(0.0777195); //fluidsmooth Real area(0.193529); //fluidBig switch(i) { case 0: return n1*flux/area; case 1: return n2*flux/area; case 2: return n3*flux/area; default: return 0.0; } }
int main(int argc, char const *argv[]) { // 0 // / \ // 1 2 // / \ \ // 3 4 7 // \ / // 5 8 // \ // 6 TreeNode<int> n0(0); TreeNode<int> n1(1); TreeNode<int> n2(2); TreeNode<int> n3(3); TreeNode<int> n4(4); TreeNode<int> n5(5); TreeNode<int> n6(6); TreeNode<int> n7(7); TreeNode<int> n8(8); n0.left = &n1; n0.right = &n2; n1.left = &n3; n1.right = &n4; n4.right = &n5; n5.right = &n6; n2.right = &n7; n7.left = &n8; bool* matrix = solve(&n0); delete[] matrix; return 0; }
JSONNode ModuleManager::convertIrcChannelToJSONString(IrcChannel& channel) { JSONNode n(JSON_NODE); n.push_back(JSONNode("name", channel.name)); n.push_back(JSONNode("topic", channel.topic)); n.push_back(JSONNode("nameListFull", channel.nameListFull)); JSONNode n2(JSON_ARRAY); n2.set_name("members"); std::vector<IrcChannelMember>::iterator iter; for(iter=channel.members.begin(); iter!=channel.members.end(); ++iter) { JSONNode n3(JSON_NODE); n3.push_back(JSONNode("nick", (*iter).nick)); JSONNode n4(JSON_ARRAY); n4.set_name("modes"); for(std::uint64_t i=1; i!=std::uint64_t(1) << 52; i<<=1) { bool current_bit = ((*iter).modes & i) != 0; n4.push_back(JSONNode("flag", current_bit)); } n3.push_back(n4); n2.push_back(n3); } n.push_back(n2); return n; }
int main() { typedef node<int> node_t; // Construction node_t n1( 1, 1 ); node_t n2( 2, 1 ); node_t n3( 2, 2 ); node_t n4( 3, 3 ); // Stream insertion std::ostringstream oss; oss << n1 << ' ' << n2 << ' ' << n3 << ' ' << n4; run_test( oss.str() == "(1,1) (2,1) (2,2) (3,3)" ); // Predicates run_test( node_t::ascending( n1, n1 ) ); run_test( node_t::descending( n1, n1 ) ); run_test( !node_t::strict_ascending( n1, n1 ) ); run_test( !node_t::strict_descending( n1, n1 ) ); run_test( node_t::ascending( n1, n3 ) ); run_test( !node_t::descending( n1, n3 ) ); run_test( node_t::strict_ascending( n1, n3 ) ); run_test( !node_t::strict_descending( n1, n3 ) ); run_test( node_t::ascending( n2, n3 ) ); run_test( !node_t::descending( n2, n3 ) ); run_test( node_t::strict_ascending( n2, n3 ) ); run_test( !node_t::strict_descending( n2, n3 ) ); run_test( node_t::ascending( n1, n2 ) ); run_test( node_t::descending( n1, n2 ) ); run_test( !node_t::strict_ascending( n1, n2 ) ); run_test( !node_t::strict_descending( n1, n2 ) ); run_test( !node_t::ascending( n4, n2 ) ); run_test( node_t::descending( n4, n2 ) ); run_test( !node_t::strict_ascending( n4, n2 ) ); run_test( node_t::strict_descending( n4, n2 ) ); run_test( node_t::left_turn( n1, n2, n3 ) ); run_test( !node_t::right_turn( n1, n2, n3 ) ); run_test( node_t::strict_left_turn( n1, n2, n3 ) ); run_test( !node_t::strict_right_turn( n1, n2, n3 ) ); run_test( !node_t::left_turn( n1, n3, n2 ) ); run_test( node_t::right_turn( n1, n3, n2 ) ); run_test( !node_t::strict_left_turn( n1, n3, n2 ) ); run_test( node_t::strict_right_turn( n1, n3, n2 ) ); run_test( node_t::left_turn( n1, n3, n4 ) ); run_test( node_t::right_turn( n1, n3, n4 ) ); run_test( !node_t::strict_left_turn( n1, n3, n4 ) ); run_test( !node_t::strict_right_turn( n1, n3, n4 ) ); }
int main() { Node n1(1, NULL, NULL); Node n3(3, NULL, NULL); Node n2(2, &n1, &n3); std::cout << BinarySearchTree::contains(n2, 3); }
TEST_F(P237_DeleteNodeInALinkedList_Test, example_case) { ListNode n3(4); ListNode n2(3); n2.next = &n3; ListNode n1(2); n1.next = &n2; ListNode n0(1); n0.next = &n1; s.deleteNode(&n2); ASSERT_EQ(4, n2.next->val); }
int main(){ node n1(1); node n2(2); node n3(3); node n4(4); node n5(5); node n6(6); node n7(7); node n8(8); node n9(9); node n10(10);
void subdivide (std::vector<vector>& vertices, std::vector<triangle>& triangles) { std::vector<triangle> new_tris; for (const triangle& tri : triangles) { unsigned int a(tri[0]), b(tri[1]), c(tri[2]); unsigned int d, e, f; vector n1 (normalize(halfway(vertices[a], vertices[b]))); auto f1 (std::find (vertices.begin(), vertices.end(), n1)); if (f1 == vertices.end()) { d = vertices.size(); vertices.push_back(n1); } else { d = std::distance(vertices.begin(), f1); } vector n2 (normalize(halfway(vertices[b], vertices[c]))); auto f2 (std::find (vertices.begin(), vertices.end(), n2)); if (f2 == vertices.end()) { e = vertices.size(); vertices.push_back(n2); } else { e = std::distance(vertices.begin(), f2); } vector n3 (normalize(halfway(vertices[c], vertices[a]))); auto f3 (std::find (vertices.begin(), vertices.end(), n3)); if (f3 == vertices.end()) { f = vertices.size(); vertices.push_back(n3); } else { f = std::distance(vertices.begin(), f3); } new_tris.push_back(make_triangle(a, d, f)); new_tris.push_back(make_triangle(d, b, e)); new_tris.push_back(make_triangle(f, e, c)); new_tris.push_back(make_triangle(d, e, f)); } triangles.swap(new_tris); }
void Mesh::LoadOBJ(const QStringRef &filename, const QStringRef &local_path) { QString filepath = local_path.toString(); filepath.append(filename); std::vector<tinyobj::shape_t> shapes; std::vector<tinyobj::material_t> materials; std::string errors = tinyobj::LoadObj(shapes, materials, filepath.toStdString().c_str()); std::cout << errors << std::endl; if(errors.size() == 0) { //Read the information from the vector of shape_ts for(unsigned int i = 0; i < shapes.size(); i++) { std::vector<float> &positions = shapes[i].mesh.positions; std::vector<float> &normals = shapes[i].mesh.normals; std::vector<float> &uvs = shapes[i].mesh.texcoords; std::vector<unsigned int> &indices = shapes[i].mesh.indices; for(unsigned int j = 0; j < indices.size(); j += 3) { glm::vec3 p1(positions[indices[j]*3], positions[indices[j]*3+1], positions[indices[j]*3+2]); glm::vec3 p2(positions[indices[j+1]*3], positions[indices[j+1]*3+1], positions[indices[j+1]*3+2]); glm::vec3 p3(positions[indices[j+2]*3], positions[indices[j+2]*3+1], positions[indices[j+2]*3+2]); Triangle* t = new Triangle(p1, p2, p3); if(normals.size() > 0) { glm::vec3 n1(normals[indices[j]*3], normals[indices[j]*3+1], normals[indices[j]*3+2]); glm::vec3 n2(normals[indices[j+1]*3], normals[indices[j+1]*3+1], normals[indices[j+1]*3+2]); glm::vec3 n3(normals[indices[j+2]*3], normals[indices[j+2]*3+1], normals[indices[j+2]*3+2]); t->normals[0] = n1; t->normals[1] = n2; t->normals[2] = n3; } if(uvs.size() > 0) { glm::vec2 t1(uvs[indices[j]*2], uvs[indices[j]*2+1]); glm::vec2 t2(uvs[indices[j+1]*2], uvs[indices[j+1]*2+1]); glm::vec2 t3(uvs[indices[j+2]*2], uvs[indices[j+2]*2+1]); t->uvs[0] = t1; t->uvs[1] = t2; t->uvs[2] = t3; } this->faces.append(t); } } std::cout << "" << std::endl; //TODO: .mtl file loading } else { //An error loading the OBJ occurred! std::cout << errors << std::endl; } }
void testTypeIDBase::copyTest() { edmtest::empty e; edm::TypeIDBase id1(typeid(e)); edm::TypeIDBase id3=id1; CPPUNIT_ASSERT(!(id1 < id3)); CPPUNIT_ASSERT(!(id3 < id1)); std::string n1(id1.name()); std::string n3(id3.name()); CPPUNIT_ASSERT(n1== n3); }
int main() { graph_node<std::string> n1("A"), n2("B"), n3("C"); graph_edge<std::string> e1(n1, n2, 3.0), e2(n1, n3, 1.47), e3(n2, n1, 3.0); std::cout << std::hash<graph_edge<std::string>>()(e1) << '\n'; std::cout << std::hash<graph_edge<std::string>>()(e3) << '\n'; std::cout << std::hash<graph_edge<std::string>>()(e2) << '\n'; if (e1 == e3) { std::cout << "e1 == e3\n"; } }
void MyMoneyPriceTest::testValidity() { QString emptyId; MyMoneyPrice n1(emptyId, QString("to"), QDate(2005, 9, 23), MyMoneyMoney(1, 3), QString("MySource")); MyMoneyPrice n2(QString("from"), emptyId, QDate(2005, 9, 23), MyMoneyMoney(1, 3), QString("MySource")); MyMoneyPrice n3(QString("from"), QString("to"), QDate(), MyMoneyMoney(1, 3), QString("MySource")); MyMoneyPrice n4(QString("from"), QString("to"), QDate(2005, 9, 23), MyMoneyMoney(1, 3), QString("MySource")); QVERIFY(n1.isValid() == false); QVERIFY(n2.isValid() == false); QVERIFY(n3.isValid() == false); QVERIFY(n4.isValid() == true); }
/** * 円柱を構築する。(カラー版) * 側面のみ。上面と底面はなし。 */ void VBORenderManager::addCylinder(const QString& geoName, const glm::mat4& modelMat, float baseRadius, float topRadius, float height, const QColor& color, int slices, int stacks) { std::vector<Vertex> verts; for (int i = 0; i < stacks; ++i) { float z1 = height / stacks * i; float z2 = height / stacks * (i + 1); float radius1 = (topRadius - baseRadius) / stacks * i + baseRadius; float radius2 = (topRadius - baseRadius) / stacks * (i + 1) + baseRadius; for (int j = 0; j < slices; ++j) { float theta1 = 2.0 * M_PI * j / slices; float theta2 = 2.0 * M_PI * (j + 1) / slices; float x1 = radius1 * cosf(theta1); float y1 = radius1 * sinf(theta1); float x2 = radius1 * cosf(theta2); float y2 = radius1 * sinf(theta2); float x3 = radius2 * cosf(theta2); float y3 = radius2 * sinf(theta2); float x4 = radius2 * cosf(theta1); float y4 = radius2 * sinf(theta1); glm::vec4 p1(x1, y1, z1, 1.0f); glm::vec4 p2(x2, y2, z1, 1.0f); glm::vec4 p3(x3, y3, z2, 1.0f); glm::vec4 p4(x4, y4, z2, 1.0f); p1 = modelMat * p1; p2 = modelMat * p2; p3 = modelMat * p3; p4 = modelMat * p4; glm::vec4 n1(x1, y1, sqrtf(x1*x1+y1*y1) / height * (baseRadius - topRadius), 0.0f); glm::vec4 n2(x2, y2, sqrtf(x2*x2+y2*y2) / height * (baseRadius - topRadius), 0.0f); glm::vec4 n3(x3, y3, sqrtf(x3*x3+y3*y3) / height * (baseRadius - topRadius), 0.0f); glm::vec4 n4(x4, y4, sqrtf(x4*x4+y4*y4) / height * (baseRadius - topRadius), 0.0f); n1 = modelMat * n1; n2 = modelMat * n2; n3 = modelMat * n3; n4 = modelMat * n4; verts.push_back(Vertex(glm::vec3(p1), color, glm::vec3(n1), glm::vec3())); verts.push_back(Vertex(glm::vec3(p2), color, glm::vec3(n2), glm::vec3())); verts.push_back(Vertex(glm::vec3(p3), color, glm::vec3(n3), glm::vec3())); verts.push_back(Vertex(glm::vec3(p1), color, glm::vec3(n1), glm::vec3())); verts.push_back(Vertex(glm::vec3(p3), color, glm::vec3(n3), glm::vec3())); verts.push_back(Vertex(glm::vec3(p4), color, glm::vec3(n4), glm::vec3())); } } addStaticGeometry(geoName, verts, "", GL_TRIANGLES, 1|mode_Lighting); }
static void TestPDFDict(skiatest::Reporter* reporter) { std::unique_ptr<SkPDFDict> dict(new SkPDFDict); assert_emit_eq(reporter, *dict, "<<>>"); dict->insertInt("n1", SkToSizeT(42)); assert_emit_eq(reporter, *dict, "<</n1 42>>"); dict.reset(new SkPDFDict); assert_emit_eq(reporter, *dict, "<<>>"); dict->insertInt("n1", 42); assert_emit_eq(reporter, *dict, "<</n1 42>>"); dict->insertScalar("n2", SK_ScalarHalf); SkString n3("n3"); std::unique_ptr<SkPDFArray> innerArray(new SkPDFArray); innerArray->appendInt(-100); dict->insertObject(n3, std::move(innerArray)); assert_emit_eq(reporter, *dict, "<</n1 42\n/n2 .5\n/n3 [-100]>>"); dict.reset(new SkPDFDict); assert_emit_eq(reporter, *dict, "<<>>"); dict->insertInt("n1", 24); assert_emit_eq(reporter, *dict, "<</n1 24>>"); dict->insertInt("n2", SkToSizeT(99)); assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99>>"); dict->insertScalar("n3", SK_ScalarHalf); assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5>>"); dict->insertName("n4", "AName"); assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName>>"); dict->insertName("n5", SkString("AnotherName")); assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n" "/n5 /AnotherName>>"); dict->insertString("n6", "A String"); assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n" "/n5 /AnotherName\n/n6 (A String)>>"); dict->insertString("n7", SkString("Another String")); assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n" "/n5 /AnotherName\n/n6 (A String)\n/n7 (Another String)>>"); dict.reset(new SkPDFDict("DType")); assert_emit_eq(reporter, *dict, "<</Type /DType>>"); }
void runEmptyRelationNoMemberCountTagTest() { //add some nodes to a map OsmMapPtr map(new OsmMap()); ElementPtr n1(new Node(Status::Unknown1, 1, 0, 0, 0)); ElementPtr n2(new Node(Status::Unknown2, 2, 0, 0, 0)); ElementPtr n3(new Node(Status::Unknown1, 3, 0, 0, 0)); ElementPtr n4(new Node(Status::Unknown2, 4, 0, 0, 0)); map->addElement(n1); map->addElement(n2); map->addElement(n3); map->addElement(n4); //create two reviews involving the two pairs of nodes ReviewMarker reviewMarker; reviewMarker.mark(map, n1, n2, "note 1", "test 1"); reviewMarker.mark(map, n3, n4, "note 2", "test 2"); CPPUNIT_ASSERT_EQUAL((size_t)2, map->getRelations().size()); CPPUNIT_ASSERT(reviewMarker.isNeedsReview(map, n1, n2)); CPPUNIT_ASSERT(reviewMarker.isNeedsReview(map, n3, n4)); //get the review relations set<ElementId> review1 = reviewMarker._getReviewRelations(map, n1->getElementId()); CPPUNIT_ASSERT_EQUAL((size_t)1, review1.size()); const ElementId r1Id = *review1.begin()++; set<ElementId> review2 = reviewMarker._getReviewRelations(map, n3->getElementId()); CPPUNIT_ASSERT_EQUAL((size_t)1, review2.size()); const ElementId r2Id = *review2.begin()++; RelationPtr relation1 = map->getRelation(r1Id.getId()); RelationPtr relation2 = map->getRelation(r2Id.getId()); //go ahead and remove their review member count tags relation1->getTags().remove(MetadataTags::HootReviewMembers()); relation2->getTags().remove(MetadataTags::HootReviewMembers()); //remove all of one of the review relation's members RemoveElementOp::removeElement(map, n3->getElementId()); RemoveElementOp::removeElement(map, n4->getElementId()); relation2->removeElement(n3->getElementId()); relation2->removeElement(n4->getElementId()); //run the visitor RemoveInvalidReviewRelationsVisitor v; map->visitRw(v); //the empty review relation should have been removed CPPUNIT_ASSERT_EQUAL((size_t)1, map->getRelations().size()); CPPUNIT_ASSERT(map->containsElement(r1Id)); CPPUNIT_ASSERT(!map->containsElement(r2Id)); }
void PyVariableTests::testPyTape(){ AbsExpNodeSptr n; PyTape t; PyExpNode n1(1,0,0,1,1,2,1); // this means t1=d0+d1 PyExpNode n2(1,0,2,2,1,2,2); // this means t2=d0*t1 PyExpNode n3(0,0,43,2,2,2,3); // this means t3=log(t2) t.push_back_node(n1); t.push_back_node(n2); t.push_back_node(n3); n = t.decode(active_node_vec, temp_node_vec); std::vector<double> dvec{16,2,77,29, 30}; CPPUNIT_ASSERT(n->get_value(dvec)==log(288.0)); }
int main() { // init data TreeNode n6(6); TreeNode n2(2); TreeNode n8(8); TreeNode n0(0); TreeNode n4(4); TreeNode n7(7); TreeNode n9(9); TreeNode n3(3); TreeNode n5(5); n6.left = &n2; n6.right = &n8; n2.left = &n0; n2.right = &n4; n8.left = &n7; n8.right = &n9; n4.left = &n3; n4.right = &n5; // 测试 fillMapParents Solution sol; map<TreeNode*, TreeNode*> mapParents; sol.fillMapParents(&n6, mapParents); sol.printMapParents(mapParents); // 测试 depth sol.printAllNodesDepth(mapParents, &n6); // 测试 traverseUpward TreeNode* tempNode = &n2; sol.traverseUpward(tempNode, 1, mapParents); // 测试 lowestCommonAncestor TreeNode* v = &n2; TreeNode* w = &n4; TreeNode* lca = sol.lowestCommonAncestor(&n6, v, w); cout << endl << v->val << ", " << w->val << " 的 LCA 是 " << lca->val << endl << endl; v = &n2; w = &n8; lca = sol.lowestCommonAncestor(&n6, v, w); cout << endl << v->val << ", " << w->val << " 的 LCA 是 " << lca->val << endl << endl; return 0; }
int main(){ TreeNode n0(10); TreeNode n1(5); TreeNode n2(15); TreeNode n3(6); TreeNode n4(20); n0.left = &n1; n0.right = &n2; n2.left = &n3; n2.right = &n4; bool res = isValidBST(&n0); printf("%s\n", res?"true":"false"); return 0; }
int main() { typedef DAG::Node<const idpair> INode; // create a set of nodes // the nodes will be kept track of in the Node children and parent collections so // shared_ptr is used. INode n0(idpair(0, 2)); INode n1(idpair(1, 3)); INode n2(idpair(2, 3)); INode n3(idpair(3, 2)); INode n4(idpair(4, 2)); INode n5(idpair(5, 2)); INode n6(idpair(6, 2)); // and now define the polytree // add the directed (parent -> child) branches of the polytree // each link requires an addChild and an addParent n0.addChild(n1); // link between n0 and n1 n1.addChild(n2); // link between n0 and n2 etc n1.addChild(n3); n3.addChild(n6); n3.addChild(n4); n4.addChild(n5); n5.addChild(n6); DAG::BFSRecurseVisitor<INode> bfs; // Start at node 0 for the following examples // Example 1 // BFSVisitor uses an iterative method to traverse // output the Datatype of all children std::cout << std::endl << "TRAVERSE CHILDREN (start Node 0) 1 level" << std::endl; for (auto n : bfs.traverseChildren(n0, 1)) { std::cout << n->value().itype << ":" << n->value().ivalue << std::endl; } std::cout << std::endl << "TRAVERSE UNDIRECTED (start Node 5) 2 levels " << std::endl; for (auto n : bfs.traverseUndirected(n5, 2)) { std::cout << n->value().itype << ":" << n->value().ivalue << std::endl; } std::cout << std::endl << "TRAVERSE CHILDREN (start Node 0) all levels" << std::endl; for (auto n : bfs.traverseChildren(n0)) { std::cout << n->value().itype << ":" << n->value().ivalue << std::endl; } return 0; }