void Transform(const std::string &from, const std::string &to, const HashSet &dict) { if (dict.count(from) && dict.count(to)) { std::queue<std::string> queue; std::map<std::string, std::string> back_track_map; queue.push(from); back_track_map[from] = ""; while (!queue.empty()) { std::string cur = queue.front(); queue.pop(); if (cur == to) { PrintPath(from, to, back_track_map); std::cout << std::endl; return; } else { for (int i = 0; i < cur.length(); i++) { for (char j = 'A'; j <= 'Z'; j++) { std::string new_word = cur; new_word.replace(i, 1, 1, j); if (dict.count(new_word) && !back_track_map.count(new_word)) { queue.push(new_word); back_track_map[new_word] = cur; } } } } } } std::cout << "There is no path from " << from << " to " << to << std::endl; }
bool CheckHeapTracer::check(AutoLockForExclusiveAccess& lock) { // The analysis thinks that markRuntime might GC by calling a GC callback. JS::AutoSuppressGCAnalysis nogc; rt->gc.markRuntime(this, GCRuntime::TraceRuntime, lock); while (!stack.empty()) { WorkItem item = stack.back(); if (item.processed) { stack.popBack(); } else { parentIndex = stack.length() - 1; TraceChildren(this, item.thing); stack.back().processed = true; } } if (oom) return false; if (failures) { fprintf(stderr, "Heap check: %zu failure(s) out of %" PRIu32 " pointers checked\n", failures, visited.count()); } MOZ_RELEASE_ASSERT(failures == 0); return true; }
TEST(FileSystemIterator, multipleFiles) { TestDirectory rootDir(File("foobarfolder")); rootDir.addFile("foobar1.txt"); rootDir.addFile("foobar2.txt"); rootDir.addFile("foobar3.txt"); rootDir.addFile("foobar4.txt"); rootDir.addFile("foobar5.txt"); HashSet<String> filenames; filenames.put("foobar1.txt"); filenames.put("foobar2.txt"); filenames.put("foobar3.txt"); filenames.put("foobar4.txt"); filenames.put("foobar5.txt"); FileSystemIterator iter(rootDir.getFile()); while (iter.isValid()) { EXPECT_TRUE(filenames.hasElement(iter->getFileName())); filenames.remove(iter->getFileName()); iter.next(); } EXPECT_EQ(0u, filenames.count()); }
TEST(FileSystemIterator, defaultAcceptTest) { // setup TestDirectory rootDir(File("foobarfolder")); rootDir.addFile("foobar1.txt"); rootDir.addDirectory("foobar")->addFile("foobar2.txt"); HashSet<String> filenames; filenames.put("foobar1.txt"); filenames.put("foobar"); filenames.put("foobar2.txt"); FileSystemIterator iter(rootDir.getFile()); EXPECT_TRUE(iter.isValid()); EXPECT_TRUE(filenames.hasElement(iter->getFileName())); filenames.remove(iter->getFileName()); EXPECT_TRUE(iter.next()); EXPECT_TRUE(filenames.hasElement(iter->getFileName())); filenames.remove(iter->getFileName()); EXPECT_TRUE(iter.next()); EXPECT_TRUE(filenames.hasElement(iter->getFileName())); filenames.remove(iter->getFileName()); EXPECT_EQ(0u, filenames.count()); EXPECT_FALSE(iter.next()); EXPECT_FALSE(iter.isValid()); // iterate again, but don't finish FileSystemIterator iter2(rootDir.getFile()); }
TEST(FileSystemIterator, subSubDirs) { TestDirectory rootDir(File("foobarfolder")); TestDirectoryPtr subDir1 = rootDir.addDirectory("subdir1"); TestDirectoryPtr subDir2 = rootDir.addDirectory("subdir2"); TestDirectoryPtr subDir3 = rootDir.addDirectory("subdir3"); subDir1->addDirectory("sub1subdir1")->addFile("sub1subdir1file1")->addFile("sub1subdir1file2"); subDir1->addDirectory("sub1subdir2")->addFile("sub1subdir2file1")->addFile("sub1subdir2file2"); subDir1->addDirectory("sub1subdir3")->addFile("sub1subdir3file1")->addFile("sub1subdir3file2"); subDir2->addDirectory("sub2subdir1")->addFile("sub2subdir1file1")->addFile("sub2subdir1file2"); subDir2->addDirectory("sub2subdir2")->addFile("sub2subdir2file1")->addFile("sub2subdir2file2"); subDir2->addDirectory("sub2subdir3")->addFile("sub2subdir3file1")->addFile("sub2subdir3file2"); subDir3->addDirectory("sub3subdir1")->addFile("sub3subdir1file1")->addFile("sub3subdir1file2"); subDir3->addDirectory("sub3subdir2")->addFile("sub3subdir2file1")->addFile("sub3subdir2file2"); subDir3->addDirectory("sub3subdir3")->addFile("sub3subdir3file1")->addFile("sub3subdir3file2"); HashSet<String> filenames; filenames.put("subdir1"); filenames.put("subdir2"); filenames.put("subdir3"); filenames.put("sub1subdir1"); filenames.put("sub1subdir2"); filenames.put("sub1subdir3"); filenames.put("sub2subdir1"); filenames.put("sub2subdir2"); filenames.put("sub2subdir3"); filenames.put("sub3subdir1"); filenames.put("sub3subdir2"); filenames.put("sub3subdir3"); filenames.put("sub1subdir1file1"); filenames.put("sub1subdir2file1"); filenames.put("sub1subdir3file1"); filenames.put("sub2subdir1file1"); filenames.put("sub2subdir2file1"); filenames.put("sub2subdir3file1"); filenames.put("sub3subdir1file1"); filenames.put("sub3subdir2file1"); filenames.put("sub3subdir3file1"); filenames.put("sub1subdir1file2"); filenames.put("sub1subdir2file2"); filenames.put("sub1subdir3file2"); filenames.put("sub2subdir1file2"); filenames.put("sub2subdir2file2"); filenames.put("sub2subdir3file2"); filenames.put("sub3subdir1file2"); filenames.put("sub3subdir2file2"); filenames.put("sub3subdir3file2"); FileSystemIterator iter(rootDir.getFile()); while (iter.isValid()) { EXPECT_TRUE(filenames.hasElement(iter->getFileName())); EXPECT_EQ(CAPU_OK, filenames.remove(iter->getFileName())); iter.next(); } EXPECT_EQ(0u, filenames.count()); }