Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .idea/$PRODUCT_WORKSPACE_FILE$

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions PlaylistChallenge.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>
35 changes: 34 additions & 1 deletion src/main/java/io/zipcoder/Music.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,39 @@ public Music(String[] playList){
}

public Integer selection(Integer startIndex, String selection){
return null;
int clickUp = 0;
int clickDown = 0;

//move forward through the array
for(int i = startIndex ; i <= playList.length; i++){

if(playList[i].equals(selection)){
break;
}
clickUp++;
/*if we get to the end of the playlist and don't find our song, we'll have to
start at the other end and keep on counting, bewaring of an infinite loop
*/
if (i == (playList.length - 1)) {
i = -1;
}
}

//move backwards through the array
for(int j = startIndex; j >= 0 ; j--){

if(playList[j].equals(selection)){
break;
}
clickDown++;
if (j == 0) {
j = playList.length;
}
}

//return whichever counter is smaller
//Math.min was auto-suggested from an if statement
//it will return the smaller number
return Math.min(clickUp, clickDown);
}
}
50 changes: 46 additions & 4 deletions src/test/java/io/zipcoder/MusicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
public class MusicTest {

@Test
public void selectionTest1(){
public void selectionTest1() {

String[] playlist = {"wheniseeyouagain","borntorun","nothingelsematters","cecelia"};
String[] playlist = {"wheniseeyouagain", "borntorun", "nothingelsematters", "cecelia"};
Music music = new Music(playlist);
Integer startingIndex = 1;
String selection = "cecelia";
Expand All @@ -18,14 +18,56 @@ public void selectionTest1(){
}

@Test
public void selectionTest2(){
public void selectionTest2() {

String[] playlist = {"dancinginthedark","rio","liveoak","liveoak"};
String[] playlist = {"dancinginthedark", "rio", "liveoak", "liveoak"};
Music music = new Music(playlist);
Integer startingIndex = 0;
String selection = "liveoak";
Integer expected = 1;
Integer actual = music.selection(startingIndex, selection);
Assert.assertEquals(expected, actual);
}

@Test
public void selectionTest3() {

String[] playlist = {"heyjude", "inmylife", "letitbe", "ijustseenaface",
"isawherstandingthere", "tickettoride", "help", "paperbackwriter", "harddaysnight"};
Music music = new Music(playlist);
Integer startingIndex = 2;
String selection = "tickettoride";
Integer expected = 3;
Integer actual = music.selection(startingIndex, selection);
Assert.assertEquals(expected, actual);
}

//test to wrap around the bottom of the array
@Test
public void selectionTest4() {

String[] playlist = {"bohemianrhapsody", "killerqueen", "fatbottomedgirls", "underpressure",
"iwantobreakfree", "somebodytolove", "flashgordontheme", "crazylittlethingcalledlove", "wearethechampions"};
Music music = new Music(playlist);
Integer startingIndex = 1;
String selection = "crazylittlethingcalledlove";
Integer expected = 3;
Integer actual = music.selection(startingIndex, selection);
Assert.assertEquals(expected, actual);
}


//test to wrap around the top of the array
@Test
public void selectionTest5() {
String[] playlist = {"tinydancer", "downtletthesungodownonme", "yoursong", "saturday",
"bennyandthejets", "crocodilerock"};
Music music = new Music(playlist);
Integer startingIndex = 5;
String selection = "tinydancer";
Integer expected = 1;
Integer actual = music.selection(startingIndex, selection);
Assert.assertEquals(expected, actual);
}
}

Binary file added target/classes/io/zipcoder/Music.class
Binary file not shown.
Binary file added target/test-classes/io/zipcoder/MusicTest.class
Binary file not shown.