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
2 changes: 2 additions & 0 deletions PlaylistChallenge.iml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
<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" />
<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>
61 changes: 54 additions & 7 deletions src/main/java/io/zipcoder/Music.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,61 @@
package io.zipcoder;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Music {

private String[] playList;

public Music(String[] playList){
this.playList = playList;
}
public Music(String[] playList)
{this.playList = playList;}

public Integer selection(Integer startIndex, String selection)
{
//Use an ArrayList
List<String> songList = Arrays.asList(this.playList);

/*The formula for forward takes the index of the selection
and minus the startIndex then Math.abs*/
int indexOfSelection = songList.indexOf(selection);
int indexDifference = indexOfSelection - startIndex;
int forwardClicks = Math.abs(indexDifference);

/*The formula for backwardClicks adds the size of the array plus the startIndex
* and subtracts the last index of the array. In essance it finds the distance without
* physically looping backwards */
int listSize = songList.size();
int sizePlusStart = listSize + startIndex;
int lastIndexOfSelection = songList.lastIndexOf(selection);
int backwardClicks = Math.abs(sizePlusStart) - lastIndexOfSelection;


//then compares the two values for backwardClicks and forwardClicks and returns the minimum
return Math.min(forwardClicks, backwardClicks);

}}

public Integer selection(Integer startIndex, String selection){
return null;
}
}
//// public Integer selectionn(Integer startIndex, String selection)
//// {
//// //Use an ArrayList
//// ArrayList<String> songList = new ArrayList<String>(Arrays.asList(this.playList));
////
//// /*The formula for forward takes the index of the selection
//// and minus the startIndex then Math.abs*/
////
//// int forwardClicks = Math.abs(songList.indexOf(selection) - startIndex);
////
//// /*The formula for backwardClicks adds the size of the array plus the startIndex
//// * and subtracts the last index of the array. In essance it finds the distance without
//// * physically looping backwards */
////
//// int backwardClicks = Math.abs(songList.size() + startIndex) - (songList.lastIndexOf(selection));
////
////
//// //then compares the two values for backwardClicks and forwardClicks and returns the minimum
////
//// return Math.min(forwardClicks, backwardClicks);
////
//// }
//}
32 changes: 27 additions & 5 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,36 @@ 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 = {"Changes", "I Will Always Love You", "Trap Queen", "Changes", "Can't Be Touched"};
Music music = new Music(playList);
Integer startingIndex = 1;
String selection = "Changes";
Integer expected = 1;
Integer actual = music.selection(startingIndex, selection);
Assert.assertEquals(expected, actual); }

@Test
public void selectionTest4()
{
String [] playList = {"Changes", "I Will Always Love You", "Trap Queen", "You Came To Do This", "I Miss You", "Changes"};
Music music = new Music(playList);
Integer startingIndex = 2;
String selection = "Changes";
Integer expected = 2;
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.