Search in sources :

Example 11 with Match

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);
}
Also used : ArrayList(java.util.ArrayList) Match(com.thebluealliance.androidclient.models.Match) Test(org.junit.Test)

Example 12 with Match

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);
}
Also used : Match(com.thebluealliance.androidclient.models.Match) Nullable(androidx.annotation.Nullable)

Example 13 with Match

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);
}
Also used : Match(com.thebluealliance.androidclient.models.Match) Test(org.junit.Test)

Example 14 with Match

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;
}
Also used : MatchType(com.thebluealliance.androidclient.types.MatchType) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout) JsonObject(com.google.gson.JsonObject) View(android.view.View) Match(com.thebluealliance.androidclient.models.Match)

Example 15 with Match

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;
}
Also used : MatchType(com.thebluealliance.androidclient.types.MatchType) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout) JsonObject(com.google.gson.JsonObject) View(android.view.View) Match(com.thebluealliance.androidclient.models.Match)

Aggregations

Match (com.thebluealliance.androidclient.models.Match)23 JsonObject (com.google.gson.JsonObject)8 MatchType (com.thebluealliance.androidclient.types.MatchType)6 Test (org.junit.Test)6 LayoutInflater (android.view.LayoutInflater)5 View (android.view.View)5 FrameLayout (android.widget.FrameLayout)5 ArrayList (java.util.ArrayList)4 Event (com.thebluealliance.androidclient.models.Event)3 Nullable (androidx.annotation.Nullable)2 JsonParseException (com.google.gson.JsonParseException)2 MatchSortByPlayOrderComparator (com.thebluealliance.androidclient.comparators.MatchSortByPlayOrderComparator)2 EventMatchesEvent (com.thebluealliance.androidclient.eventbus.EventMatchesEvent)2 MatchAlliancesContainer (com.thebluealliance.androidclient.models.MatchAlliancesContainer)2 Team (com.thebluealliance.androidclient.models.Team)2 List (java.util.List)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 WorkerThread (androidx.annotation.WorkerThread)1 MatchSortByDisplayOrderComparator (com.thebluealliance.androidclient.comparators.MatchSortByDisplayOrderComparator)1