use of com.thebluealliance.androidclient.models.Match in project the-blue-alliance-android by the-blue-alliance.
the class MatchHelperTest method testGetNextMatchPlayed.
@Test
public void testGetNextMatchPlayed() {
List<Match> matches;
Match nextMatch;
// Empty cases
assertNull(MatchHelper.getNextMatchPlayed(null));
assertNull(MatchHelper.getNextMatchPlayed(new ArrayList<>()));
// No matches played
matches = mockMatchList(10);
nextMatch = MatchHelper.getNextMatchPlayed(matches);
assertEquals(nextMatch, matches.get(0));
// One block of matches played
markMatchesPlayed(matches, 0, 4);
nextMatch = MatchHelper.getNextMatchPlayed(matches);
assertEquals(nextMatch, matches.get(4));
// Data gap
markMatchesPlayed(matches, 6, 8);
nextMatch = MatchHelper.getNextMatchPlayed(matches);
assertEquals(nextMatch, matches.get(8));
// All matches played
markMatchesPlayed(matches, 0, 10);
nextMatch = MatchHelper.getNextMatchPlayed(matches);
assertNull(nextMatch);
}
use of com.thebluealliance.androidclient.models.Match in project the-blue-alliance-android by the-blue-alliance.
the class MatchHelper method getNextMatchPlayed.
/**
* Returns the match object of the match next to be played
* Iterate backwards to account for data gaps
*
* @param matches ArrayList of matches. Assumes the list is sorted by play order
* @return Next match
*/
@Nullable
public static Match getNextMatchPlayed(List<Match> matches) {
if (matches == null || matches.isEmpty())
return null;
Match last = null;
for (int i = matches.size() - 1; i >= 0; i--) {
Match m = matches.get(i);
if (m.hasBeenPlayed()) {
return last;
}
last = m;
}
// no matches played
return matches.get(0);
}
use of com.thebluealliance.androidclient.models.Match in project the-blue-alliance-android by the-blue-alliance.
the class MyTbaModelRendererTest method testRenderMatch.
@Test
public void testRenderMatch() {
Match match = ModelMaker.getModel(Match.class, MATCH_KEY);
when(mDatafeed.fetchMatch(MATCH_KEY)).thenReturn(Observable.just(match));
mRenderer.renderFromKey(MATCH_KEY, ModelType.MATCH, null);
verify(mMatchRenderer).renderFromModel(match, MatchRenderer.RENDER_DEFAULT);
}
use of com.thebluealliance.androidclient.models.Match in project the-blue-alliance-android by the-blue-alliance.
the class MatchBreakdownView2015Test method getView.
private MatchBreakdownView2015 getView(String matchJsonFile) {
Match match = ModelMaker.getModel(Match.class, matchJsonFile);
LayoutInflater inflater = LayoutInflater.from(InstrumentationRegistry.getTargetContext());
View view = inflater.inflate(R.layout.fragment_match_breakdown, null, false);
FrameLayout matchView = (FrameLayout) view.findViewById(R.id.match_breakdown);
assertEquals(1, matchView.getChildCount());
assertTrue(matchView.getChildAt(0) instanceof MatchBreakdownView2015);
MatchBreakdownView2015 view2015 = (MatchBreakdownView2015) matchView.getChildAt(0);
MatchType matchType = MatchType.fromKey(match.getKey());
view2015.initWithData(matchType, match.getWinningAlliance(), match.getAlliances(), mGson.fromJson(match.getScoreBreakdown(), JsonObject.class));
view2015.setVisibility(View.VISIBLE);
// hide progress bar
view.findViewById(R.id.progress).setVisibility(View.GONE);
return view2015;
}
use of com.thebluealliance.androidclient.models.Match in project the-blue-alliance-android by the-blue-alliance.
the class MatchBreakdownView2017Test method getView.
private MatchBreakdownView2017 getView(String matchJsonFile) {
Match match = ModelMaker.getModel(Match.class, matchJsonFile);
LayoutInflater inflater = LayoutInflater.from(InstrumentationRegistry.getTargetContext());
View view = inflater.inflate(R.layout.fragment_match_breakdown, null, false);
FrameLayout matchView = (FrameLayout) view.findViewById(R.id.match_breakdown);
assertEquals(1, matchView.getChildCount());
assertTrue(matchView.getChildAt(0) instanceof MatchBreakdownView2017);
MatchBreakdownView2017 view2017 = (MatchBreakdownView2017) matchView.getChildAt(0);
MatchType matchType = MatchType.fromKey(match.getKey());
view2017.initWithData(matchType, match.getWinningAlliance(), match.getAlliances(), mGson.fromJson(match.getScoreBreakdown(), JsonObject.class));
view2017.setVisibility(View.VISIBLE);
// hide progress bar
view.findViewById(R.id.progress).setVisibility(View.GONE);
return view2017;
}
Aggregations