def insertScoreToList(scoreList, s1, s2, s3, position): """ Insert a score pair at a given position in list :param scoreList: list of scores :param score: score pair to be added :param position: position where it needs to be added :return: nothing """ try: position = int(position) if position < 1: raise BaseException scoreList.insert(position - 1, UTILS.getNewScore(s1, s2, s3)) if position > len(scoreList) - 1: print("The score will be inserted at the end of the list\ \nsince the position is higher than the size of the list.") except BaseException as be: print("Invalid position or score.")
def addScoreToList(scoreList, *scores): """ Add a score pair to list :param scoreList: list of scores :param score: score pair to be added :return: nothing """ # try: # scoreList.append(UTILS.getNewScore(s1, s2, s3)) # except BaseException as be: # UI.invalidScores() try: if not len(scores) % 3 == 0: raise AttributeError for i in range(0, len(scores), 3): scoreList.append( UTILS.getNewScore(scores[i], scores[i + 1], scores[i + 2])) except AttributeError as ae: UI.invalidNumberOrArgs() except BaseException as be: UI.invalidScores()
def test_reset_score(): sc = UTILS.getNewScore(1, 2, 3) UTILS.resetScore(sc) assert sc == [0, 0, 0], "Reset score error"
def test_get_new_score(): assert UTILS.getNewScore(1, 2, 3) == [1, 2, 3], "New score error"
def test_comp_operator(): op = "<" scorePair = UTILS.getNewScore(1, 2, 3) assert UTILS.compareWithOperator(scorePair, op, 10) == (6 < 10), "Compare with operator error"
def test_insert_score(): list = [[1, 2, 3]] CMDS.insertScoreToList(list, 4, 5, 6, 1) assert len(list) == 2 and list[0] == UTILS.getNewScore(4, 5, 6), "Insert error"