// -------------------- EDAC Tests ---------------------- void FileAccessControllerTests::doTestEDAC(EntityDataAccessController *edac) { StartTrace(FileAccessControllerTests.doTestEDAC); if (t_assert(edac != NULL)) { String user("user"), guest("guest"), unknown("unknown"), coffee("coffee"); Anything groups; groups.Append("coffee"); groups.Append("movies"); Anything allowed; Anything empty = Anything(Anything::ArrayMarker()); // empty group t_assert(edac->GetAllowedEntitiesForGroup(guest, allowed)); t_assert(!allowed.IsNull()); assertEqual(0L, allowed.GetSize()); // single group t_assert(edac->GetAllowedEntitiesForGroup(user, allowed)); assertEqual(2L, allowed.GetSize()); t_assert(allowed.Contains("changePW")); t_assert(allowed.Contains("resetPW")); // group list t_assert(edac->GetAllowedEntitiesForGroups(groups, allowed)); assertEqual(5L, allowed.GetSize()); t_assert(allowed.Contains("tv")); t_assert(allowed.Contains("espressomachine")); t_assert(!allowed.Contains("changePW")); t_assert(edac->GetAllowedEntitiesForGroups(empty, allowed)); t_assert(!allowed.IsNull()); assertEqual(0L, allowed.GetSize()); // specific tests t_assert(edac->IsAllowed(user, "resetPW")); t_assert(edac->IsAllowed(coffee, "cookiejar")); t_assert(!edac->IsAllowed(guest, "everything")); // tests with unknown t_assert(!edac->IsAllowed(unknown, "format c:")); t_assert(!edac->GetAllowedEntitiesForGroup(unknown, allowed)); empty.Append(coffee); empty.Append(unknown); t_assert(!edac->GetAllowedEntitiesForGroups(empty, allowed)); } }
int main() { Recipe recipe; CaffeineBeverage coffee(std::bind(&Recipe::amountWater, &recipe, 150), std::bind(&Recipe::brewCoffee, &recipe)); CaffeineBeverage tea(std::bind(&Recipe::amountWater, &recipe, 100), std::bind(&Recipe::brewTea, &recipe)); std::vector<CaffeineBeverage*> beverages; beverages.push_back(&coffee); beverages.push_back(&tea); for(auto it = beverages.begin(); it != beverages.end(); it++) { (*it)->prepare(); } return 0; }
int main() { setlocale(LC_ALL, "Russian"); int Cellsizex=10, Cellsizey=10, CellOutlineThickness=1; sf::RenderWindow window(sf::VideoMode().getDesktopMode(), "Life", sf::Style::None); LIFE A(window.getSize().x, window.getSize().y, Cellsizex, Cellsizey, CellOutlineThickness); //initialization of rectangles (cells) sf::RectangleShape rectangle(sf::Vector2f(Cellsizex, Cellsizey)); rectangle.setFillColor(sf::Color::Black); sf::Color coffee(68, 45, 37); rectangle.setOutlineColor(coffee); rectangle.setOutlineThickness(CellOutlineThickness); A.Set("random"); A.Output(window, rectangle); unsigned int generations=0; std::cout << "Window size (width õ height) " << window.getSize().x << 'x' << window.getSize().y << std::endl; int xmouse, ymouse; while (window.isOpen()) { if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) { xmouse=sf::Mouse::getPosition(window).x; ymouse=sf::Mouse::getPosition(window).y; std::cout << xmouse << ' ' << ymouse << " " << std::endl; if(xmouse<Cellsizex) xmouse=0; else xmouse=xmouse/(Cellsizex+CellOutlineThickness); if(ymouse<Cellsizey) ymouse=0; else ymouse=ymouse/(Cellsizey+CellOutlineThickness); std::cout << xmouse << ' ' << ymouse << " " << std::endl; A.Set(xmouse, ymouse); } window.clear(); A.GenChange(); generations++; Sleep(100); A.Output(window, rectangle); window.display(); gotoxy(0,2); std::cout << "Generations: " << generations << " " << std::endl; Event(window, A); gotoxy(0,5); std::cout << "RowsxCols: " << A.getrows() << 'x' << A.getcols() << " " << std::endl; } _getch(); return 0; }