def test_prob_experiment(self): hat = prob_calculator.Hat(blue=3, red=2, green=6) probability = prob_calculator.experiment(hat=hat, expected_balls={ "blue": 2, "green": 1 }, num_balls_drawn=4, num_experiments=1000) actual = probability expected = 0.272 self.assertAlmostEqual( actual, expected, delta=0.01, msg='Expected experiemnt method to return a different probability.' ) hat = prob_calculator.Hat(yellow=5, red=1, green=3, blue=9, test=1) probability = prob_calculator.experiment(hat=hat, expected_balls={ "yellow": 2, "blue": 3, "test": 1 }, num_balls_drawn=20, num_experiments=100) actual = probability expected = 1.0 self.assertAlmostEqual( actual, expected, delta=0.01, msg='Expected experiment method to return a different probability.' )
def test_hat_draw(self): hat = prob_calculator.Hat(red=5, blue=2) actual = hat.draw(2) expected = ['blue', 'red'] # self.assertEqual(actual, expected, 'Expected hat draw to return two random items from hat contents.') actual = len(hat.contents) expected = 5
def test_experiment(self): bucket = prob_calculator.Hat(red=4, black=4) ex = prob_calculator.experiment(bucket, expected_balls={'red': 1, 'black': 1}, num_balls_drawn=2, num_experiments=1000) actual = ex expected = 0.5714 self.assertAlmostEqual(actual, expected, delta=0.02, msg='Expected a different probability.')
def test_hat_class_contents(self): hat = prob_calculator.Hat(red=3, blue=2) actual = hat.contents expected = ["red", "red", "red", "blue", "blue"] self.assertEqual( actual, expected, 'Expected creation of hat object to add correct contents.')
def test_Hat(self): bowler = prob_calculator.Hat(magenta=5, cerulean=5, polkadot=1) actual = bowler.contents expected = ['magenta', 'magenta', 'magenta', 'magenta', 'magenta', 'cerulean', 'cerulean', 'cerulean', 'cerulean', 'cerulean', 'polkadot'] self.assertEqual(actual, expected, 'Expected a Hat obj with contents matching kwarg types.')
def test_hat_draw_less_balls(self): hat = prob_calculator.Hat(red=1, blue=2) actual = hat.draw(4) expected = ["red", "blue", "blue"] self.assertEqual( actual, expected, "Expected hat draw to return all the items from hat contents.", ) actual = len(hat.contents) expected = 0 self.assertEqual( actual, expected, "Expected hat draw to reduce number of items in contents.")
def test_hat_draw(self): hat = prob_calculator.Hat(red=5, blue=2) actual = hat.draw(2) expected = ["blue", "red"] self.assertEqual( actual, expected, "Expected hat draw to return two random items from hat contents.", ) actual = len(hat.contents) expected = 5 self.assertEqual( actual, expected, "Expected hat draw to reduce number of items in contents.")
# This entrypoint file to be used in development. Start by reading README.md import prob_calculator from unittest import main hat = prob_calculator.Hat(blue=4, red=2, green=6, black=10) probability = prob_calculator.experiment(hat=hat, expected_balls={ "green": 1, "blue": 1, "black": 10 }, num_balls_drawn=15, num_experiments=10000) print("Probability:", probability) # Run unit tests automatically main(module='test_module', exit=False)
import prob_calculator hat1 = prob_calculator.Hat(black=6, red=4, green=3) probability = prob_calculator.experiment(hat=hat1, expected_balls={ "red": 2, "green": 1 }, num_balls_drawn=5, num_experiments=10000) print("Probability: ", probability)
# This entrypoint file to be used in development. Start by reading README.md import prob_calculator from unittest import main hat = prob_calculator.Hat(blue=1, red=1) probability = prob_calculator.experiment( hat=hat, expected_balls={"red": 1}, num_balls_drawn=1, num_experiments=3000) print("Probability:", probability) # Run unit tests automatically main(module='test_module', exit=False)
from tkinter import * from tkinter import ttk def click_add_button(): user_hat.add_color_ball(color.get(), amount.get()) print(user_hat) # So, now we are going to create a small interface so that a user can continue to run these simulations # as long as they see fit. For that, we are going to use tkinter. # 1. We have to create the environment for the user, they need an empty hat to add balls into. # 2. We had to create an "add_color_ball" function to the hat class because the interface functions differently # from the way the test_module uses it. We have to give the user the ability to add ass many colors they want to # the hat. user_hat = prob_calculator.Hat() # 3. Now we have to create the interface using tkinter. # We initialize the window and set a title. root = Tk() root.title("Probability Calculator") root.geometry("350x300") # This is the frame for the next part of the program. This part requires the user to create a list of what they expect # the outcome of the random draw should be. The list will be continually updated and displayed on the right hand side # in a new frame. I need to learn how to make my frames the same size to make it look better, or maybe get rid of the # visual part of the frames and add these steps, that the user must do to make the program run, into a continuously # updating frame, where the user hits a "next" button and the screen changes and you're on to the next step, """ root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1)
def test_draw(self): beret = prob_calculator.Hat(cyan=3, sienna=3) beret.draw(3) actual = len(beret.contents) expected = 3 self.assertEqual(actual, expected, 'Expected draw to remove items from contents.')
# This entrypoint file to be used in development. Start by reading README.md import prob_calculator from unittest import main hat = prob_calculator.Hat(blue=4, red=2, green=6) probability = prob_calculator.experiment(hat=hat, expected_balls={ "blue": 2, "red": 1 }, num_balls_drawn=4, num_experiments=3000) print("Probability:", probability) # Run unit tests automatically main(module='test_module', exit=False) hat = prob_calculator.Hat(red=5, orange=4, black=1, blue=0, pink=2, striped=9)
import prob_calculator as pc hat = pc.Hat(red=5, orange=4, black=1, blue=1, pink=2, striped=9) color, amount = hat.unpack() print('List of balls : \n') for i, j in zip(color, amount): print(i, j) hat, \ expected_balls, \ num_balls_drawn, \ num_experiments, \ prob = pc.experiment(hat=hat, expected_balls={"red":2,"orange":3, 'striped':1}, num_balls_drawn=6, num_experiments=101) print('\nExpected balls: ', expected_balls) print('Number balls drawn: ', num_balls_drawn) print('Number experiments: ', num_experiments) print("Probability: ", prob)
import prob_calculator from unittest import main hat = prob_calculator.Hat(blue=3, red=2, green=6) probability = prob_calculator.experiment(hat=hat, expected_balls={ "blue": 2, "green": 1 }, num_balls_drawn=4, num_experiments=1000) # print(len(hat.contents)) print("Probability:", probability) hat = prob_calculator.Hat(yellow=5, red=1, green=3, blue=9, test=1) # print(len(hat.contents)) probability = prob_calculator.experiment(hat=hat, expected_balls={ "yellow": 2, "blue": 3, "test": 1 }, num_balls_drawn=20, num_experiments=100) print("Probability:", probability) # Run unit tests automatically # main(module='test_module', exit=False)
# This entrypoint file to be used in development. Start by reading README.md import prob_calculator from unittest import main hat = prob_calculator.Hat(blue=9, red=1, green=3, yellow=5, test=1) probability = prob_calculator.experiment(hat=hat, expected_balls={ "blue": 3, "yellow": 2, "test": 1 }, num_balls_drawn=20, num_experiments=10) print("Probability:", probability) # Run unit tests automatically main(module='test_module', exit=False)
# This entrypoint file to be used in development. Start by reading README.md import prob_calculator from unittest import main hat = prob_calculator.Hat(blue=4, red=2, green=6) probability = prob_calculator.experiment(hat=hat, expected_balls={ "blue": 2, "red": 1 }, num_balls_drawn=4, num_experiments=2000) print("Probability:", probability) # Run unit tests automatically main(module='test_module', exit=False)
# This entrypoint file to be used in development. Start by reading README.md import prob_calculator from unittest import main hat1 = prob_calculator.Hat(yellow=3, blue=2, green=6) print(hat1.contents) print(hat1.draw(5)) hat = prob_calculator.Hat(blue=3, red=2, green=6) probability = prob_calculator.experiment(hat=hat, expected_balls={ "blue": 2, "green": 1 }, num_balls_drawn=4, num_experiments=2000) print(probability) # Run unit tests automatically main(module='test_module', exit=False)