Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Here is the test code: import unittest from CC1.solution import story_progression from random import seed, randint class CC1Tests(unittest.TestCase): def test_basic(self): test1 = [0, 1,

image text in transcribed

Python

Here is the test code:

import unittest from CC1.solution import story_progression from random import seed, randint

class CC1Tests(unittest.TestCase):

def test_basic(self): test1 = [0, 1, 1, 1, 0, 0, 0] question1 = [(0, 2)] expected = ['Win'] actual = story_progression(test1, question1) self.assertEqual(expected, actual)

test2 = [0, 1, 1, 1] question2 = [(0, 1), (0, 2), (0, 3)] question2.sort() expected = ['Lose', 'Win', 'Win'] actual = story_progression(test2, question2) self.assertEqual(expected, actual)

test3 = [1, 0, 0, 0] question3 = [(0, 0), (0, 3)] expected = ['Win', 'Lose'] actual = story_progression(test3, question3) self.assertEqual(expected, actual)

def test_ask_zero_one_elements(self): test1 = [0, 1, 1, 0, 1] question1 = [(0, 0)] expected = ['Lose'] actual = story_progression(test1, question1) self.assertEqual(expected, actual)

test2 = [1, 1, 0, 0] question2 = [(0, 0)] expected = ['Win'] actual = story_progression(test2, question2) self.assertEqual(expected, actual)

test3 = [1, 1, 0, 0] question3 = [] expected = [] actual = story_progression(test3, question3) self.assertEqual(expected, actual)

def test_duplicate(self): seed(331) test1 = [0, 1, 0, 1, 1, 0] question1 = [(0, 2), (0, 2), (0, 4), (0, 4)]

expected = ['Lose', 'Lose', 'Win', 'Win']

actual = story_progression(test1, question1) self.assertEqual(expected, actual)

test2 = [randint(0, 331) % 2 for _ in range(10)] question2 = [(0, randint(0, 9)) for _ in range(5)] question2 = question2 * 2 question2.sort() expected = ['Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Lose', 'Lose', 'Lose', 'Lose'] actual = story_progression(test2, question2) self.assertEqual(expected, actual)

def test_ask_whole(self): seed(2021331)

test1 = [0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1] question1 = [(0, i) for i in range(len(test1))] question1.sort() expected = ['Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Win', 'Win', 'Win', 'Win'] actual = story_progression(test1, question1) self.assertEqual(expected, actual)

test2 = [1] question2 = [(0, 0)] expected = ["Win"] actual = story_progression(test2, question2) self.assertEqual(expected, actual)

test3 = [0] question3 = [(0, 0)] expected = ["Lose"] actual = story_progression(test3, question3) self.assertEqual(expected, actual)

def test_short_questions_random_input(self): seed(331)

generate1 = 1234567 test1 = [1 if generate1 & (1

actual = story_progression(test1, question1) self.assertEqual(expected, actual)

test2 = [randint(0, 331) % 2 for _ in range(100)] question2 = [(0, 0), (0, 2), (0, 5), (0, 11), (0, 98), (0, 99), (0, 99)] question2.sort() expected = ['Win', 'Win', 'Win', 'Win', 'Lose', 'Lose', 'Lose'] actual = story_progression(test2, question2) self.assertEqual(expected, actual)

def test_large_input(self): seed(2033121)

test1 = [0] * 25 + [1] * 30 + [0] * 25 + [1] * 120 # Pattern of 1 and zero question1 = [(0, randint(0, len(test1) - 1)) for _ in range(50)] question1.sort()

expected = ['Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Win', 'Win', 'Win', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Lose', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win', 'Win']

if __name__ == '__main__': unittest.main()

Ex. 1: answers: (0, 1, 1, 1, 0, 0, 0] questions: [[0, 2]] Result: ['Win'] Looking at Ex. 1, the given range in the answers list is [0, 1, 1, 1, 0, 0, 0]. Note that there are two l's and one 0 in the given range from index 0 to index 2. Thus, the Result list should contain 'Win' since there are more l's than O's. Ex. 2: answers: (0, 1, 1, 1] questions: [(0, 1), (0, 2), (0, 3)] Result: ['Lose Win, 'Win'] Ex. 2 contains three question tuples in the questions list Question 1: The first question in the list [(0, 1), (0, 2), (0, 3)] wants you to look at the numbers contained in the index range 0 to 1 of the answers list. In the given range (0, 1) in the answers list [0, 1, 1, 1], there's one 0 and one 1, so there isn't a strict majority of l's. This results in a 'Lose' state being added to the Result list. Question 2: The second question in the list [(0,1),(0, 2), (0, 3)] wants you to look at the numbers contained in the index range 0 to 2 of the answers list. In the given range (0, 2) in the answers list ([0, 1, 1, 1]) there's one 0 and two l's, so there is a strict majority of l's. This results in a 'Win' state being added to the Result list. Question 3: The third question in the list ([(0, 1), (0, 2), (0, 3)] wants you to look at the numbers contained in the index range 0 to 3 of the answers list. In the given range (0, 3) in the answers list ([0, 1, 1, 1]) there's one 0 and three l's so there is a strict majority of I's. This results in a 'Win' state being added to the Result list. After analyzing all of the questions in the questions list, the Results list would be: ['Lose', 'Win', 'Win']

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions

Question

Describe the visual representations, or models, of communication

Answered: 1 week ago

Question

1. Who should participate and how will participants be recruited?

Answered: 1 week ago