id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
9f9ed5f8-0cbc-42a1-9ef6-3480ac676b48 | public MyDog() {
// TODO Auto-generated constructor stub
super("dog right.png","dog left.png", .35);
} |
8606f123-c6b8-45bd-aed9-4e60f973ad70 | public MyMouse() {
// TODO Auto-generated constructor stub
super("mouse left.png", "mouse right.png", .15);
} |
67bce0ca-740a-485b-b424-06e03a6f58c3 | public HealthItem(double width, double height) {
super(width, height);
// TODO Auto-generated constructor stub
} |
d0d63baa-a4fe-4df5-8e1e-cf736dc45791 | public void testSearchContactAndText() throws RemoteException, UiObjectNotFoundException {
UiDevice uiDevice = UiDevice.getInstance();
uiDevice.pressHome();
uiDevice.setOrientationNatural();
// KeyguardManager mKeyGuardManager = new Keyg(KeyguardManager) getSystemService(KEYGUARD_SERVICE); mLock = mKeyGuardManager.newKeyguardLock("activity_classname"); mLock.disableKeyguard();where activity_classname is the class name of the activity.
UiObject appUiObject = new UiObject(new UiSelector().descriptionContains("Apps"));
appUiObject.clickAndWaitForNewWindow();
UiObject targetAppUiObject = new UiObject(new UiSelector().text("Talk.to"));
new UiScrollable(new UiSelector().resourceId("com.android.launcher:id/apps_customize_pane_content")).setAsHorizontalList().scrollIntoView(targetAppUiObject);
targetAppUiObject.clickAndWaitForNewWindow();
UiObject homeScreenUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/menu_home_activity_start_conversation"));
UiObject chatIconUiObject = new UiObject(new UiSelector().text("CHATS"));
if (!homeScreenUiObject.exists() || !chatIconUiObject.exists()) {
uiDevice.pressBack();
}
searchContact();
} |
75df8faf-c74b-4dfc-a327-6c56a041d99a | private void searchContact() throws UiObjectNotFoundException {
// to.talk:id/search_box
UiObject searchUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/menu_home_activity_search_contact"));
searchUiObject.clickAndWaitForNewWindow();
UiObject searchEditTextUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/search_box"));
if (searchEditTextUiObject.getText().toString().equals("Search")) // cos of hint text.
{
// searchEditTextUiObject.setText(searchEditTextUiObject.getText());
searchEditTextUiObject.setText("Anshu");
// UiObject noContactFoundUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/footer_text"));
// if(noContactFoundUiObject.isEnabled())
// {
// // NO CONTACTS FOUND
// }
// else
// {
UiScrollable contactListUiScrollable = new UiScrollable(new UiSelector().resourceId("to.talk:id/list"));
UiObject foundContactUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/title").textContains("Anshu"));
contactListUiScrollable.scrollIntoView(foundContactUiObject);
foundContactUiObject.clickAndWaitForNewWindow();
sendText1();
//writeText();
// }
} else {
searchEditTextUiObject.setText("EMPTYYYYYYYYYYYYYY");
}
} |
37eb6460-25dd-4de8-8f6b-7c31b50f176f | private void writeText() {
UiObject writeMessageUiObject = new UiObject(new UiSelector().packageName("to.talk").className("android.widget.EditText").resourceId("to.talk:id/message_field"));
UiObject contentSharingBtn = new UiObject(new UiSelector().resourceId("to.talk:id/content_sharing_btn"));
try {
//new UiObject(new UiSelector().resourceId("to.talk:id/message_field")).setText("TEST");
if (writeMessageUiObject.waitForExists(5000)) {
System.out.print("Found text box");
writeMessageUiObject.setText("Test");
//contentSharingBtn.click();
} else System.out.print("Failed to find textbox");
// to.talk:id/message_field
// writeMessageUiObject.click();
// writeMessageUiObject.clearTextField();
// writeMessageUiObject.setText("Hii this is random automated text");
sendText();
} catch (UiObjectNotFoundException e) {
//IF I HAVE TO PRINT SOMETHING ACC TO ME????????????
e.printStackTrace();
}
} |
aec59f23-b0e8-4b4e-9b6b-dd538211a0b3 | private void sendText() throws UiObjectNotFoundException {
UiObject sendMessageButtonUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/send"));
sendMessageButtonUiObject.click();
} |
0cce6d02-cd18-4187-8bea-326a477372fe | public void sendText1() {
UiObject messageTextbox = new UiObject(new UiSelector().packageName("to.talk").resourceId("to.talk:id/message_field"));
UiObject sendButton = new UiObject(new UiSelector().packageName("to.talk").resourceId("to.talk:id/send"));
if (messageTextbox.waitForExists(5000)) {
try {
messageTextbox.setText("Test123");
} catch (UiObjectNotFoundException e) {
System.out.print("Failed to write");
e.printStackTrace();
}
} else System.out.print("Failed to find the textbox");
try {
sendButton.click();
} catch (UiObjectNotFoundException e) {
System.out.print("Failed to tap send");
e.printStackTrace();
}
} |
c6228e91-d136-4d67-b495-d862d357e76d | public void testAudio() throws UiObjectNotFoundException, RemoteException {
UiDevice uiDevice = UiDevice.getInstance();
uiDevice.pressHome();
uiDevice.setOrientationNatural();
UiObject appUiObject = new UiObject(new UiSelector().descriptionContains("Apps"));
appUiObject.clickAndWaitForNewWindow();
UiObject targetAppUiObject = new UiObject(new UiSelector().text("Talk.to"));
new UiScrollable(new UiSelector().resourceId("com.android.launcher:id/apps_customize_pane_content")).setAsHorizontalList().scrollIntoView(targetAppUiObject);
targetAppUiObject.clickAndWaitForNewWindow();
UiObject homeScreenUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/menu_home_activity_start_conversation"));
UiObject chatIconUiObject = new UiObject(new UiSelector().text("CHATS"));
if (!homeScreenUiObject.exists() || !chatIconUiObject.exists()) {
uiDevice.pressBack();
}
searchContact();
} |
9285e624-6d6b-47f0-8089-a18e5f7b13e3 | private void searchContact() throws UiObjectNotFoundException {
UiObject searchUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/menu_home_activity_search_contact"));
searchUiObject.clickAndWaitForNewWindow();
UiObject searchEditTextUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/search_box"));
searchEditTextUiObject.setText("Anshu");
UiScrollable contactListUiScrollable = new UiScrollable(new UiSelector().resourceId("to.talk:id/list"));
UiObject foundContactUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/title").textContains("Anshu"));
contactListUiScrollable.scrollIntoView(foundContactUiObject);
foundContactUiObject.clickAndWaitForNewWindow();
selectAudio();
} |
cdbc0d69-3c10-495e-b9da-c61d30656e96 | private void selectAudio() throws UiObjectNotFoundException {
UiObject sharingUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/content_sharing_btn"));
sharingUiObject.click();
} |
550f6bb1-f04a-43fd-86ec-c31649ac5872 | private void sendAudio() {
} |
ede3a163-c6be-4412-aaa1-f873e59b59a2 | public void testDemo() throws UiObjectNotFoundException {
// UiObject ttApp = new UiObject(new UiSelector().packageName("com.android.launcher").text("Talk.to"));
//
// ttApp.clickAndWaitForNewWindow();
// UiDevice myDevice = UiDevice.getInstance();
//
// myDevice.pressHome();
//
// UiObject appDrawerUiObject = new UiObject(new UiSelector().descriptionContains("Apps"));
//
// appDrawerUiObject.clickAndWaitForNewWindow();
//
// UiObject targetApp = new UiObject(new UiSelector().text("Talk.to"));
//
// new UiScrollable(new UiSelector().resourceId("com.android.launcher:id/apps_customize_pane_content")).setAsHorizontalList().scrollIntoView(targetApp);
//
// targetApp.clickAndWaitForNewWindow();
UiDevice uiDevice = UiDevice.getInstance();
uiDevice.pressHome();
UiObject appUiObject = new UiObject(new UiSelector().descriptionContains("Apps"));
appUiObject.clickAndWaitForNewWindow();
UiObject targetAppUiObject = new UiObject(new UiSelector().text("Talk.to"));
new UiScrollable(new UiSelector().resourceId("com.android.launcher:id/apps_customize_pane_content")).setAsHorizontalList().scrollIntoView(targetAppUiObject);
targetAppUiObject.clickAndWaitForNewWindow();
} |
8d164715-df24-4e31-8423-c01041bcdadb | public void testOpenTalkToThroughAppMenu() throws UiObjectNotFoundException, RemoteException {
UiDevice uiDevice = UiDevice.getInstance();
uiDevice.pressHome();
uiDevice.setOrientationNatural();
// KeyguardManager mKeyGuardManager = new Keyg(KeyguardManager) getSystemService(KEYGUARD_SERVICE); mLock = mKeyGuardManager.newKeyguardLock("activity_classname"); mLock.disableKeyguard();where activity_classname is the class name of the activity.
UiObject appUiObject = new UiObject(new UiSelector().descriptionContains("Apps"));
appUiObject.clickAndWaitForNewWindow();
UiObject targetAppUiObject = new UiObject(new UiSelector().text("Talk.to"));
new UiScrollable(new UiSelector().resourceId("com.android.launcher:id/apps_customize_pane_content")).setAsHorizontalList().scrollIntoView(targetAppUiObject);
targetAppUiObject.clickAndWaitForNewWindow();
UiObject tabSwipeObject = new UiObject(new UiSelector().resourceId("to.talk:id/viewpager"));
new UiScrollable(new UiSelector().resourceId("to.talk:id/viewpager")).setAsHorizontalList().scrollIntoView(targetAppUiObject);
tabSwipeObject.swipeRight(500);
//tabSwipeObject.swipeLeft(0);
} |
88642d0d-01b5-4140-af91-a2bec591a757 | public void testDemo() throws UiObjectNotFoundException {
// Simulate a short press on the HOME button.
getUiDevice().pressHome();
// We’re now in the home screen. Next, we want to simulate
// a user bringing up the All Apps screen.
// If you use the uiautomatorviewer tool to capture a snapshot
// of the Home screen, notice that the All Apps button’s
// content-description property has the value “Apps”. We can
// use this property to create a UiSelector to find the button.
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
// Simulate a click to bring up the All Apps screen.
allAppsButton.clickAndWaitForNewWindow();
// In the All Apps screen, the Settings app is located in
// the Apps tab. To simulate the user bringing up the Apps tab,
// we create a UiSelector to find a tab with the text
// label “Apps”.
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
// Simulate a click to enter the Apps tab.
appsTab.click();
// Next, in the apps tabs, we can simulate a user swiping until
// they come to the Settings app icon. Since the container view
// is scrollable, we can use a UiScrollable object.
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
// Set the swiping mode to horizontal (the default is vertical)
appViews.setAsHorizontalList();
// Create a UiSelector to find the Settings app and simulate
// a user click to launch the app.
UiObject settingsApp = appViews.getChildByText(new UiSelector()
.className(android.widget.TextView.class.getName()),"Settings");
settingsApp.clickAndWaitForNewWindow();
// Validate that the package name is the expected one
UiObject settingsValidation = new UiObject(new UiSelector().packageName("com.android.settings"));
assertTrue("Unable to detect Settings",settingsValidation.exists());
} |
630f0273-805b-4c24-9941-60b0a91b6e71 | public void testRough() throws UiObjectNotFoundException
{
UiObject textBox = new UiObject(new UiSelector().packageName("to.talk").resourceId("to.talk:id/message_field"));
UiObject sendButton = new UiObject(new UiSelector().packageName("to.talk").resourceId("to.talk:id/message_field"));
textBox.setText("test345");
sendButton.click();
} |
48f3ff25-85bd-43f6-818d-01414ba4b813 | public void testSearchContactAndText() throws RemoteException, UiObjectNotFoundException
{
String searchText = getParams().getString("search");
String newString = "";
if(searchText.contains("%nbsp"))
{
newString = searchText.replaceAll("%nbsp", " ");
System.out.print("Searched Text"+newString);
}
UiDevice uiDevice = UiDevice.getInstance();
uiDevice.pressHome();
uiDevice.setOrientationNatural();
UiObject appUiObject = new UiObject(new UiSelector().descriptionContains("Apps"));
appUiObject.clickAndWaitForNewWindow();
long initialTime = System.currentTimeMillis();
UiObject targetAppUiObject = new UiObject(new UiSelector().text("Talk.to"));
long openedTime = System.currentTimeMillis();
long timeTakenToOpenTheApp = openedTime-initialTime;
System.out.print("LAUNCH TIME"+timeTakenToOpenTheApp);
new UiScrollable(new UiSelector().resourceId("com.android.launcher:id/apps_customize_pane_content")).setAsHorizontalList().scrollIntoView(targetAppUiObject);
targetAppUiObject.clickAndWaitForNewWindow();
UiObject homeScreenUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/menu_home_activity_start_conversation"));
UiObject chatIconUiObject = new UiObject(new UiSelector().text("CHATS"));
if(!homeScreenUiObject.exists() || !chatIconUiObject.exists())
{
uiDevice.pressBack();
}
searchContact(newString);
} |
b417f175-14f0-4072-89ed-3cd2d2edab5c | private void searchContact(String searchText) throws UiObjectNotFoundException
{
// to.talk:id/search_box
UiObject searchUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/menu_home_activity_search_contact"));
searchUiObject.clickAndWaitForNewWindow();
UiObject searchEditTextUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/search_box"));
if(searchEditTextUiObject.getText().toString().equals("Search")) // cos of hint text.
{
searchEditTextUiObject.setText(searchText);
// UiObject noContactFoundUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/footer_text"));
// if(noContactFoundUiObject.isEnabled())
// {
// // NO CONTACTS FOUND
// }
// else
// {
UiScrollable contactListUiScrollable = new UiScrollable(new UiSelector().resourceId("to.talk:id/list"));
UiObject foundContactUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/title").textContains(searchText));
contactListUiScrollable.scrollIntoView(foundContactUiObject);
foundContactUiObject.clickAndWaitForNewWindow();
writeText();
// }
}
else
{
searchEditTextUiObject.setText("EMPTYYYYYYYYYYYYYY");
}
} |
9b5b8193-8160-4451-95cf-c3cc6c83331c | private void writeText()
{
// UiObject writeMessageUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/message_field"));
try
{
new UiObject(new UiSelector().resourceId("to.talk:id/message_field")).setText("TEST");
// writeMessageUiObject.click();
// writeMessageUiObject.clearTextField();
// writeMessageUiObject.setText("Hii this is random automated text");
sendText();
}
catch (UiObjectNotFoundException e)
{
//IF I HAVE TO PRINT SOMETHING ACC TO ME????????????
e.printStackTrace();
}
} |
9f7da381-8ea1-415c-928d-fa70b5278dd7 | private void sendText() throws UiObjectNotFoundException
{
UiObject sendMessageButtonUiObject = new UiObject(new UiSelector().resourceId("to.talk:id/send"));
sendMessageButtonUiObject.click();
} |
9fc10b88-90e1-4960-be62-27c1a962e106 | public StockPrice(int dayNumber, double price) {
this.dayNumber = dayNumber;
this.price = price;
} |
5103c3ea-2939-4a92-9e1a-a559a36707f8 | public int getDayNumber() {
return dayNumber;
} |
b64708e0-cba4-45d7-9062-b49e858e402c | public void setDayNumber(int dayNumber) {
this.dayNumber = dayNumber;
} |
e9b44c04-e0b7-4d38-b1f6-1143bbd0e7b3 | public double getPrice() {
return price;
} |
c7ceb463-edaf-4aff-b538-096fd3930540 | public void setPrice(double price) {
this.price = price;
} |
cd08cf53-5843-4947-83d9-7fee6851803e | public String getActionName() {
return type.toString();
} |
cfa886b9-4d7d-47ea-9e97-aadb95020117 | public String getDetails() {
return null;
} |
f9c994e9-ceb7-4811-accd-628e04b136dd | public int getDayNumber() {
return dayNumber;
} |
a0e8bf61-8fad-4dbb-894d-618aa5313527 | public ActionType getType() {
return type;
} |
fc47352d-2d47-4a95-bdc8-47feac04c061 | public Share(double initialPrice) {
this.initialPrice = initialPrice;
} |
75b4e813-817e-4a58-8adc-18fd349f8137 | public double getInitialPrice() {
return initialPrice;
} |
3c08eb0b-4879-44b7-9154-62e896c17bab | private static List<StockPrice> getStockPrices1() {
List<StockPrice> stockPrices = new LinkedList<StockPrice>();
stockPrices.add(new StockPrice(1, 2.0));
stockPrices.add(new StockPrice(2, 3.0));
stockPrices.add(new StockPrice(3, 5.0));
stockPrices.add(new StockPrice(4, 4.0));
stockPrices.add(new StockPrice(5, 1.0));
return stockPrices;
} |
2e580d03-d249-4836-a864-4c74fec1966d | private static List<StockPrice> getStockPrices2() {
List<StockPrice> stockPrices = new LinkedList<StockPrice>();
stockPrices.add(new StockPrice(1, 2.0));
stockPrices.add(new StockPrice(2, 3.0));
stockPrices.add(new StockPrice(3, 10.0));
stockPrices.add(new StockPrice(4, 4.0));
stockPrices.add(new StockPrice(5, 1.0));
stockPrices.add(new StockPrice(6, 7.0));
return stockPrices;
} |
8c4ebc5f-fc2e-4347-8011-b87caf3bd6d9 | public static void main(String[] args) {
List<StockPrice> stockPrices = getStockPrices1();
Collection<Action> bestActions = StocksGenius.getBestActions1(stockPrices);
print(stockPrices, bestActions);
} |
71a85bd2-e6d9-4461-930c-328e670ac8b3 | private static void print(Collection<StockPrice> stockPrices, Collection<Action> bestActions) {
assert stockPrices.size() == bestActions.size();
assert stockPrices.size() != 0;
Iterator<StockPrice> stockPriceIt = stockPrices.iterator();
Iterator<Action> actionIt = bestActions.iterator();
System.out.format("%-10s %-12s %-10S %-10S\n", "Day", "Stock Price", "Action", "Desc");
do {
StockPrice stockPrice = stockPriceIt.next();
Action action = actionIt.next();
System.out.format("%-10s %-12s %-10S %-10S\n", stockPrice.getDayNumber(), stockPrice.getPrice(), action.getActionName(), action.getDetails());
}
while (stockPriceIt.hasNext());
} |
485c2cae-8633-425c-8de5-306dd29dd886 | private BuySellPeriod(int periodStartDayNumber, int periodEndDayNumber, double maxSellPrice) {
assert periodStartDayNumber <= periodEndDayNumber;
this.periodStartDayNumber = periodStartDayNumber;
this.periodEndDayNumber = periodEndDayNumber;
this.maxSellPrice = maxSellPrice;
} |
f2127b5a-60a0-4edf-8a57-245563f2f1da | public int getPeriodStartDayNumber() {
return periodStartDayNumber;
} |
1b5364aa-fa97-4c97-ba49-f83324dced78 | public int getPeriodEndDayNumber() {
return periodEndDayNumber;
} |
43c897e8-bd9b-4b98-8357-7783a625daa3 | public Collection<Action> generateActionsForPeriod(Collection<StockPrice> stockPrices) {
Collection<Action> listOfActions = new LinkedList<Action>();
if (periodStartDayNumber == periodEndDayNumber) {
listOfActions.add(new PassAction(periodStartDayNumber));
return listOfActions;
}
double income = 0;
for (int i = periodStartDayNumber; i < periodEndDayNumber; i++) {
StockPrice stockPrice = getStockPriceForDay(i, stockPrices);
if (stockPrice != null) {
listOfActions.add(new BuyAction(i, new Share(stockPrice.getPrice())));
income += maxSellPrice;
} else {
listOfActions.add(new PassAction(i));
}
}
listOfActions.add(new SellAction(periodEndDayNumber, income));
return listOfActions;
} |
86bf6ba6-c3e9-41c0-9e2b-1d83781899dc | private StockPrice getStockPriceForDay(int day, Collection<StockPrice> stockPrices) {
for (StockPrice stockPrice : stockPrices) {
if (stockPrice.getDayNumber() == day) {
return stockPrice;
}
}
return null;
} |
59e84623-4520-4540-a269-cca9a30a0659 | public static Collection<Action> getBestActions1(List<StockPrice> stockPrices) {
Collection<BuySellPeriod> periods = getPeriods(stockPrices); // complexity O(N^2)
Collection<Action> actions = new LinkedList<Action>();
for (BuySellPeriod period : periods) { // complexity O(N)
actions.addAll(period.generateActionsForPeriod(stockPrices));
}
return actions;
} |
8cafaa49-967d-4697-be1b-1ba4dc16677e | private static Collection<BuySellPeriod> getPeriods(List<StockPrice> stockPricesForPeriod) {
Collection<BuySellPeriod> periods = new LinkedList<BuySellPeriod>();
StockPrice maxStockPriceForPeriod;
do {
// First we are looking for max stock price for all available days.
maxStockPriceForPeriod = getDayWithMaxStockPrice(stockPricesForPeriod); // complexity O(N)
assert maxStockPriceForPeriod != null;
// We may gain income if we will buy stocks from first day of period till day with max stock prices
periods.add(new BuySellPeriod(
stockPricesForPeriod.get(0).getDayNumber(),
maxStockPriceForPeriod.getDayNumber(),
maxStockPriceForPeriod.getPrice()));
stockPricesForPeriod = getNewPeriodStockPrices(stockPricesForPeriod, maxStockPriceForPeriod); // complexity O(N)
}
while (stockPricesForPeriod.size() != 0); // complexity O(N^2)
return periods;
} |
2b1d87dd-6166-41da-875f-98668ab43de5 | private static List<StockPrice> getNewPeriodStockPrices(List<StockPrice> stockPricesForPeriod, StockPrice maxStockPriceForPeriod) { // complexity O(N)
// Cut data for [day 1, day with max price]
List<StockPrice> stockPricesForNewPeriod = new LinkedList<StockPrice>(stockPricesForPeriod
.subList(stockPricesForPeriod.indexOf(maxStockPriceForPeriod), stockPricesForPeriod.size())); // complexity O(N)
//If new period starts with days with same price as maxStockPriceForPeriod.price, we can remove them
while (stockPricesForNewPeriod.size() != 0
&& stockPricesForNewPeriod.get(0).getPrice() == maxStockPriceForPeriod.getPrice()) { // complexity O(N)
stockPricesForNewPeriod.remove(0);
}
return stockPricesForNewPeriod;
} |
9ccb1a1c-e38b-47c9-8cc0-d1db364f28d3 | private static StockPrice getDayWithMaxStockPrice(Collection<StockPrice> stockPrices) { // complexity O(N)
assert stockPrices.size() != 0;
StockPrice maxStockPrice = stockPrices.iterator().next(); // get first element
for (StockPrice stockPrice : stockPrices) {
if (maxStockPrice.getPrice() < stockPrice.getPrice()) {
maxStockPrice = stockPrice;
}
}
return maxStockPrice;
} |
fddc66b6-e5df-4815-af0a-eafbba032ce5 | public BuyAction(int day, Share share) {
this.type = ActionType.BUY;
this.dayNumber = day;
this.share = share;
} |
11a016ec-1f77-400c-b7ee-cecaf814656c | public String getDetails() {
return "-" + String.valueOf(share.getInitialPrice());
} |
92f925ef-a745-42f7-8780-b2ca3b72d02c | public PassAction(int day) {
this.type = ActionType.PASS;
this.dayNumber = day;
} |
63343b52-aba6-49ad-8832-a37d98eed714 | public String getDetails() {
return "Pass";
} |
37f191f1-db39-4560-98cc-1d8875684b70 | public SellAction(int day, double profit) {
this.type = ActionType.SELL;
this.dayNumber = day;
this.profit = profit;
} |
a18a76fe-1354-41ee-ad28-8c8d54abf1a9 | public String getDetails() {
return "+" + String.valueOf(profit);
} |
de173d61-d857-41de-b167-752700025ea0 | public static Collection<Integer> findDuplicates(Collection<Integer> numbers) { // full complexity O(n^2)
List<Integer> duplicates = new LinkedList<Integer>();
// Set<Integer> duplicates = new HashSet<Integer>(); // if we need same order as in example
Set<Integer> processedValues = new HashSet<Integer>();
for (Integer value : numbers) { // complexity O(n^2)
if (processedValues.contains(value) && !duplicates.contains(value)) { // complexity O(n)
duplicates.add(value);
} else {
processedValues.add(value);
}
}
return duplicates;
} |
43f1bfd7-95eb-4a21-9fd1-fbf04cfca187 | public static void main(String[] args) {
Collection<Integer> numbers = Arrays.asList(6, 1, 1, 2, 3, 4, 8, 43, 5, 8, 1, 43, 2, 2, 9);
Collection<Integer> dupes = findDuplicates(numbers);
for (int dupe : dupes) {
System.out.println("dupe = " + dupe);
}
} |
0cc3d0e7-c48b-494a-9461-60835c27ebf9 | private static Collection<Email> generateTestData(RandomOrder shouldBeRandom) {
Collection<Email> emails;
if (shouldBeRandom == RandomOrder.TRUE) {
emails = new HashSet<Email>(); // can be used if we need randomly ordered input data
} else {
emails = new LinkedList<Email>();
}
// First emails
emails.add(new Email("test_01@gmail.com", "Hello, Test 01!"));
emails.add(new Email("test_02@gmail.com", "Hello, Test 02!"));
emails.add(new Email("test_03@gmail.com", "Hello, Test 03!"));
emails.add(new Email("test_04@gmail.com", "Hello, Test 04!"));
//Second emails
emails.add(new Email("test_01@gmail.com", "Hello, Test 01. It is my second email."));
emails.add(new Email("test_02@gmail.com", "Hello, Test 02. It is my second email."));
emails.add(new Email("test_03@gmail.com", "Hello, Test 02. It is my second email."));
//Third email
emails.add(new Email("test_01@gmail.com", "Hello, Test 01. Don't forget to reply me!"));
return emails;
} |
b7377db8-1923-47a4-b2a7-93ab7d5b61e3 | private static void print(Collection<Collection<Email>> emailBatches) {
int i = 1;
for (Collection<Email> batch : emailBatches) {
System.out.println("Email batch #" + i++);
for (Email email : batch) {
System.out.format(" [%s]%s\n", email.getTo(), email.getMessage());
}
}
} |
ff42f439-4751-45f3-bc36-3743b23d3264 | public static void main(String[] args) {
Collection<Email> emails = generateTestData(RandomOrder.FALSE); // switch to TRUE for randomly ordered input data
// print input emails
for (Email email : emails) {
System.out.format("[%s]%s\n", email.getTo(), email.getMessage());
}
Collection<Collection<Email>> emailBatches1 = EmailBatching.batchEmails1(emails);
print(emailBatches1);
System.out.println("Second algorithm");
// Due to usage of HashMap should be quicker then previous version
Collection<Collection<Email>> emailBatches2 = EmailBatching.batchEmails2(emails);
print(emailBatches2);
} |
cf5e0276-dcea-41e2-b888-137ae2669092 | public static Collection<Collection<Email>> batchEmails1(Collection<Email> emails) { // complexity O(N^2)
List<Collection<Email>> batchs = new LinkedList<Collection<Email>>();
// add list as first batch
batchs.add(new LinkedList<Email>());
for (Email email : emails) { // complexity O(N^2)
boolean wasAdded = false;
for (Collection<Email> batch : batchs) { // complexity O(batch_size*number_of_batches) in case of batches with sae size, but we have limited number of emails N, so can take O(N)
if (!doesButchContainRecipient(batch, email.getTo())) { // complexity O(batch_size)
batch.add(email);
wasAdded = true;
break;
}
}
if (!wasAdded) {
Collection<Email> newBatch = new LinkedList<Email>();
newBatch.add(email);
batchs.add(newBatch);
}
}
return batchs;
} |
8ec63e69-a34e-42cb-b078-74c579e72b2e | private static boolean doesButchContainRecipient(Collection<Email> batch, String emailAddress) { // complexity O(n)
for (Email email : batch) {
if (email.getTo().equals(emailAddress)) {
return true;
}
}
return false;
} |
55f29529-78f2-4f70-9435-6f8ca5b0fe8a | public static Collection<Collection<Email>> batchEmails2(Collection<Email> emails) { // complexity O(N^2)
List<Map<String, Email>> tempBatches = new LinkedList<Map<String, Email>>();
// Maps will contain pairs <EmailsAddress, EmailObject>
// add first temporary batch
tempBatches.add(new HashMap<String, Email>());
for (Email email : emails) {
boolean wasAdded = false;
for (Map<String, Email> batch : tempBatches) {
if (!batch.containsKey(email.getTo())) {
batch.put(email.getTo(), email);
wasAdded = true;
break;
}
}
if (!wasAdded) {
Map<String, Email> newBatch = new HashMap<String, Email>();
newBatch.put(email.getTo(), email);
tempBatches.add(newBatch);
}
}
List<Collection<Email>> batches = new LinkedList<Collection<Email>>();
for (Map<String, Email> temporaryBatch : tempBatches) {
batches.add(temporaryBatch.values());
}
return batches;
} |
3a3c48cd-0a17-44c2-9b49-14c824f96726 | public Email(String to, String message) {
this.to = to;
this.message = message;
} |
ce71f704-0ab5-4947-8c4f-e39ef2ea449a | public String getMessage() {
return message;
} |
9175c1fb-dc23-4a8a-a102-346eb1be3659 | public void setMessage(String message) {
this.message = message;
} |
5611645d-cc90-4ba3-b91a-f93dce30c73b | public String getTo() {
return to;
} |
ba9f4c88-121c-4a2f-94c9-ce061af06726 | public void setTo(String to) {
this.to = to;
} |
b8e09ccf-404e-4b3d-86eb-5f62e7b5dd5e | private static List<Task> getTestData() {
List<Task> tasks = new ArrayList<Task>();
Date startDate = new Date();
Date endDate = new Date();
startDate.setSeconds(0);
endDate.setSeconds(0);
startDate.setHours(12);
startDate.setMinutes(0);
endDate.setHours(13);
endDate.setMinutes(40);
tasks.add(new Task((Date) startDate.clone(), (Date) endDate.clone())); // task #1
startDate.setHours(12);
startDate.setMinutes(30);
endDate.setHours(13);
endDate.setMinutes(20);
tasks.add(new Task((Date) startDate.clone(), (Date) endDate.clone())); // task #2
startDate.setHours(13);
startDate.setMinutes(0);
endDate.setHours(13);
endDate.setMinutes(40);
tasks.add(new Task((Date) startDate.clone(), (Date) endDate.clone())); // task #3
return tasks;
} |
c444d4b8-725c-4b3e-b2bc-d3488642c78b | private static void printTasks(List<Task> tasks) {
System.out.println("Tasks:");
int i = 1;
for (Task task : tasks) {
System.out.format("%s: %02d:%02d - %02d:%02d\n", i++, task.getStart().getHours(), task.getStart().getMinutes(),
task.getEnd().getHours(), task.getEnd().getMinutes());
}
} |
4b7aa39d-5d7e-4c43-bbd5-ac8a9a268ece | private static void printPoints(Collection<Point> points) {
System.out.println("Points:");
int i = 1;
for (Point point : points) {
System.out.format("%s: %02d:%02d - %d\n", i++, point.getTime().getHours(), point.getTime().getMinutes(), point.getCount());
}
} |
96ae51a1-e1bb-4552-ab7d-4f899cdd47d7 | public static void main(String[] args) {
List<Task> tasks = getTestData();
printTasks(tasks);
Collection<Point> points = TaskToPointConverter.createPoint1(tasks);
printPoints(points);
points = TaskToPointConverter.createPoint2(tasks);
printPoints(points);
} |
e97d2f41-e10c-4400-a7ce-7388a211990c | public static Collection<Point> createPoint1(Collection<Task> tasks) { // complexity O(n^2)
TreeSet<Date> possiblePointDates = new TreeSet<Date>();
for (Task task : tasks) { // complexity O(n)
possiblePointDates.add(task.getStart());
possiblePointDates.add(task.getEnd());
}
List<Point> points = new ArrayList<Point>();
int previousCount = -1;
for (Date possiblePointDate : possiblePointDates) { // complexity O(n^2)
int countOfTasks = coutOfTasks(possiblePointDate, tasks);
if (previousCount != countOfTasks) {
points.add(new Point(possiblePointDate, countOfTasks));
previousCount = countOfTasks;
}
}
return points;
} |
4706b787-f39e-43b6-b5c7-53098e69483e | private static int coutOfTasks(Date date, Collection<Task> tasks) { // complexity O(n)
int i = 0;
for (Task task : tasks) {
if ((task.getStart().equals(date) || task.getStart().before(date))
&& task.getEnd().after(date)) {
i++;
}
}
return i;
} |
532f42d4-25f0-448a-8d84-ac907f87bb71 | public static Collection<Point> createPoint2(Collection<Task> tasks) { // complexity O(n*log_n)
TreeMap<Date, Integer> points = new TreeMap<Date, Integer>();
for (Task task : tasks) { // complexity O(n*log_n)
Date startDate = task.getStart();
Object count = points.get(startDate);
if (count != null) {
points.put(startDate, new Integer((Integer) count + 1));
} else {
points.put(startDate, new Integer(1));
}
Date endDate = task.getEnd();
count = points.get(endDate);
if (count != null) {
points.put(endDate, new Integer((Integer) count - 1));
} else {
points.put(endDate, new Integer(-1));
}
}
List<Point> result = new ArrayList<Point>();
int previousCount = 0;
for (Date date : points.keySet()) { // complexity O(n)
previousCount += points.get(date);
result.add(new Point(date, previousCount));
}
return result;
} |
9a1be124-bfad-4079-8f65-fff74dfb54eb | public Task(Date start, Date end) {
this.start = start;
this.end = end;
} |
2c566e46-41d8-4789-80f5-d132c3095731 | public Date getStart() {
return start;
} |
7a94cc60-87e5-42d4-af8e-1b5884308534 | public Date getEnd() {
return end;
} |
163625c9-3235-4f7f-b3e8-e5a7cdfbf25c | public Point(Date time, int count) {
this.time = time;
this.count = count;
} |
0ae58f99-4bde-4fe3-a0c4-a7f00799a99a | public Date getTime() {
return time;
} |
45817559-60e5-4f61-9fd7-77bc2cc509dc | public int getCount() {
return count;
} |
830471a1-2599-4ea9-936a-23db08e3c390 | public HomePage(WebDriver driver){
this.driver = driver;
driver.get(BASE_URL);
} |
0ca3cc29-e0b0-408d-a3dc-ffaaa853ba5f | public String getCompanyName(){
LOG.debug(MSG_GETTING_COMPANY_NAME);
return driver.findElement(BY_COMPANY_NAME).getText();
} |
d593c748-e619-4c75-a6d5-68f0aade056b | public String getWelcomeMessage() {
return driver.findElement(BY_WELCOME_MESSAGE).getText();
} |
3e6b2878-12d8-4c59-8548-df1278f90ab8 | public WebElement lookForElementNotOnPage(){
return driver.findElement(BY_DOES_NOT_EXIST);
} |
9b22da10-7f87-4566-8242-0ac3c62c6d23 | public HistoryPage clickQuickHistory(){
driver.findElement(BY_QUICK_HISTORY).click();
return new HistoryPage(driver);
} |
42c3021c-ba4c-46e7-8a41-76b349a9eeb7 | public boolean hasLongHistorySuccessOption(){
boolean found = false;
driver.findElement(BY_LONG_HISTORY).click();
//simpleWaitLongHistoryOpts();
fluentWaitLongHistoryOpts();
List<WebElement> options = driver.findElement(BY_LONG_HISTORY_OPTIONS).findElements(By.tagName("option"));
for(WebElement option : options){
String value = option.getAttribute(VALUE);
LOG.debug("Value: {}", value);
if(value.equals(EXPECTED_LONG_HISTORY_SUCCESS_VALUE)){
found = true;
}
}
return found;
} |
41c11af4-e007-44aa-80b2-45a70a1beaa0 | private void simpleWaitLongHistoryOpts(){
WebElement longHistoryOptions = (new WebDriverWait(driver, 20))
.until(ExpectedConditions.presenceOfElementLocated(BY_LONG_HISTORY_OPTIONS));
} |
5af5c9ec-052a-4da8-8401-d3afbbfd88d9 | private void fluentWaitLongHistoryOpts(){
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(20, TimeUnit.SECONDS)
.pollingEvery(100, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
wait.until(ExpectedConditions.elementToBeClickable(BY_LONG_HISTORY_OPTIONS));
} |
35369835-5e06-4653-af5b-270ed551bf5e | public PricingPage(WebDriver driver){
this.driver = driver;
driver.get(BASE_URL);
} |
fa7bad83-c0ea-4090-988b-ecfedbe153df | public List<String> getRateTypes(){
ArrayList results = new ArrayList();
for(WebElement priceMapping : driver.findElements(LIST_ITEM_PRICE)){
results.add(priceMapping.getText().split(":")[0]);
}
return results;
} |
7d6051dc-c4be-49bf-9a88-cff477b7e370 | public HistoryPage(WebDriver driver){
this.driver = driver;
} |
664b64f9-374a-4d7c-be8e-cbc8d93085c3 | public String getTitle(){
return driver.findElement(BY_TITLE).getText();
} |
9b3a2c3b-cd6d-40d8-bb9c-a83459c0c445 | public FunctionalTest() {
} |
442fd0cd-2115-4afb-8016-37648746513d | @BeforeClass
public static void createDriver() {
LOG.debug("Instantiating new driver.");
driver = new ChromeDriver();
} |
bd223547-60c0-4e26-93e0-2001a45e9421 | @AfterClass
public static void closeDriver() {
LOG.debug("Closing driver.");
driver.close();
} |
d84a4751-63f0-4977-ad3f-5acdf2f351bc | @Before
public void setUp(){
pricingPage = new PricingPage(driver);
} |
5a333729-37d8-4b6e-84b7-c92b1d50edf2 | @Test
public void threeRateTypesAvailable(){
assertThat(pricingPage.getRateTypes().size()).isEqualTo(3);
} |
183fb022-5e2a-47ae-9461-9b6cbe8415e0 | @Test
public void hourDayWeekPricesAvailable(){
List<String> rateTypes = pricingPage.getRateTypes();
assertThat(rateTypes).containsExactly("Hour","Day","Week");
} |
cc09054b-4a3d-4e40-964e-4944690a9448 | @Before
public void setUp(){
homePage = new HomePage(driver);
} |
76889566-0204-4bf4-9a78-ea03be46f422 | @Test
public void companyNameIsCorrect(){
assertThat(homePage.getCompanyName()).isEqualTo(HomePage.EXPECTED_COMPANY_NAME);
} |
9e6b566e-d4dd-4f13-82be-2055bba4fb71 | @Test
public void welcomeMessageIsCorrect(){
assertThat(homePage.getWelcomeMessage()).isEqualTo(HomePage.EXPECTED_WELCOME_MESSAGE);
} |
f7a3f9e7-cfc9-4e37-9029-c1de3065c397 | @Test
public void longHistoryHasSuccessOption(){
assertThat(homePage.hasLongHistorySuccessOption()).overridingErrorMessage("Success option not found!!!");
} |
dc23fc29-cd99-4d4a-a9e0-3a8083f6685d | @Test
public void getHistoryPage(){
HistoryPage historyPage = homePage.clickQuickHistory();
assertThat(historyPage.getTitle()).isEqualTo(HistoryPage.EXPECTED_TITLE);
} |
9d826f64-1441-44eb-833f-b8f404651d0b | @Test(expected = NoSuchElementException.class)
public void lookForSomethingNotOnPage(){
homePage.lookForElementNotOnPage();
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.