示例#1
0
class Test_Lootbag(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.red_bag = Lootbag('red')
        self.Amy = Kid('Amy', 1)
        self.Bruce = Kid('Bruce', 0)
        self.red_bag.kids.add(self.Amy)
        self.red_bag.kids.add(self.Bruce)
        self.Amy.add_toy('bike')
        self.Amy.add_toy('ball')
        self.Amy.add_toy('calculator')

    def test_lootbag_exists(self):
        self.assertIsInstance(self.red_bag, Lootbag)
        self.assertEqual(self.red_bag.color, 'red')
        self.assertNotEqual(self.red_bag.color, 'green')

    def test_lootbag_has_kids(self):
        self.assertEqual(len(self.red_bag.kids), 2)
        self.assertNotEqual(len(self.red_bag.kids), 0)

    def test_add_toy_to_kid(self):
        self.assertIn('bike', self.Amy.toys)
        self.assertNotIn('car', self.Amy.toys)

    def test_remove_toy_from_kid(self):
        self.Amy.add_toy('doll')
        self.assertIn('doll', self.Amy.toys)
        self.Amy.remove_toy('doll')
        self.assertNotIn('doll', self.Amy.toys)

    def test_delivery(self):
        self.Amy.delivered = False
        self.Amy.deliver_all_toys()
        self.assertTrue(self.Amy.delivered)
示例#2
0
 def setUpClass(self):
     self.red_bag = Lootbag('red')
     self.Amy = Kid('Amy', 1)
     self.Bruce = Kid('Bruce', 0)
     self.red_bag.kids.add(self.Amy)
     self.red_bag.kids.add(self.Bruce)
     self.Amy.add_toy('bike')
     self.Amy.add_toy('ball')
     self.Amy.add_toy('calculator')
示例#3
0
    def make_kids(self):
        kids = []
        for n in range(global_params.num_kids_per_family):
            new_kid = Kid(ineligible_names=self.kid_names)
            self.kid_names[new_kid.sex].append(new_kid.name)
            kids.append(new_kid)

        return kids
示例#4
0
import sys
from lootbag import Lootbag
from kid import Kid

Yellow_Bag = Lootbag('yellow')
Candace = Kid('candace', 1)
Derek = Kid('derek', 0)
Yellow_Bag.kids.add(Candace)
Yellow_Bag.kids.add(Derek)
Candace.add_toy('crayons')

# Requirements
# 1. Add a toy: (3 args): the word "add", the name of the gift, the name of the child (lootbag.py add kite suzy)
# remove suzy kite
# list children currently receiving presents (using the ls command)
# list all toys for a specific child (ls suzy)
# mark all of a child's toys delivered (delivered suzy)

if len(sys.argv) > 1 and sys.argv[1] == "add":
    # add kite suzy
    # !This looks like it works, but it doesn't. Can't figure out why. It says the toy is added to the list, but printing the list shows that it isn't added. Unit testing shows that the toy DOES get added so IDFK.
    for k in Yellow_Bag.kids:
        if (sys.argv[3]).capitalize() == k.name:
            k.add_toy(sys.argv[2])
            k.toy_list()
elif len(sys.argv) > 1 and sys.argv[1] == "remove":
    # remove suzy kite
    # !Because the add command doesn't work, this one doesn't work. You can't remove a toy if it isn't in there in the first place.
    for k in Yellow_Bag.kids:
        if (sys.argv[2]) == k.name:
            k.remove_toy(sys.argv[3])
示例#5
0
文件: run.py 项目: dramatis/dramatis
#!/usr/bin/env python

import inspect
import sys
import os.path

sys.path[0:0] = [ os.path.join( os.path.dirname( inspect.getabsfile( inspect.currentframe() ) ), '..', '..', '..', 'lib' ) ]
sys.path[0:0] = [ os.path.join( os.path.dirname( inspect.getabsfile( inspect.currentframe() ) ), '..' ) ]

from kid import Kid

tom = Kid( "Tom" )
becky = Kid( "Becky", tom )
dick = Kid( "Dick", becky )
jane = Kid( "Jane", dick )
harry = Kid( "Harry", jane )
sally = Kid( "Sally", harry )

phrases = [ "his mom locked her keys in the car, " + \
            "so he should get a ride home with Hector",
            "Mac King is a comedy magic genius" ]

for phrase in phrases:
    print "Teacher:", phrase
    sally.whisper( phrase )

for phrase in phrases:
    print "Teacher heard:", tom.ask()
示例#6
0
        """Returns the list of deliveries by child"""
        print("----- Delivery List -----")
        for k in self.kids:
            if k.is_nice == True and k.toys and k.delivered == False:
                print(k.toy_list())
            if k.is_nice == False and k.delivered == False:
                print(f"*** {k.name}'s Toy List ***")
                print('Coal')

    def __str__(self):
        return f"This bag is colored {self.color}."


if __name__ == '__main__':
    Blue_Bag = Lootbag('blue')
    Amy = Kid('amy', 1)
    Bruce = Kid('bruce', 0)
    Blue_Bag.kids.add(Amy)
    Blue_Bag.kids.add(Bruce)
    Amy.add_toy('bike')
    Amy.add_toy('sailboat')
    Amy.add_toy('ball')

    print(Blue_Bag)
    Blue_Bag.kid_list()
    Blue_Bag.delivery_list()
    Amy.deliver_all_toys()
    Bruce.deliver_all_toys()
    Amy.deliver_all_toys()
    Bruce.deliver_all_toys()
示例#7
0
文件: run.py 项目: dramatis/dramatis
#!/usr/bin/env python

import inspect
import sys
import os.path

sys.path[0:0] = [ os.path.join( os.path.dirname( inspect.getabsfile( inspect.currentframe() ) ), '..', '..', '..', 'lib' ) ]
sys.path[0:0] = [ os.path.join( os.path.dirname( inspect.getabsfile( inspect.currentframe() ) ), '..' ) ]

from kid import Kid

tom = Kid( "Tom" )
becky = Kid( "Becky", tom )
dick = Kid( "Dick", becky )
jane = Kid( "Jane", dick )
harry = Kid( "Harry", jane )
sally = Kid( "Sally", harry )

phrase = "his mom locked her keys in the car, " + \
         "so he should get a ride home with Hector"

print "Teacher:", phrase
sally.whisper( phrase )
示例#8
0
from man import Man
from boy import Boy
from kid import Kid


def atThePark(man):
    print("In the park")
    man.play()


man = Man()
boy = Boy()
kid = Kid()
boy.play()
boy.walk()
boy.eat()
kid.play()
atThePark(man)
atThePark(kid)
atThePark(boy)
示例#9
0
文件: run.py 项目: halorgium/dramatis
#!/usr/bin/env python

import inspect
import sys
import os.path

sys.path[0:0] = [os.path.join(os.path.dirname(inspect.getabsfile(inspect.currentframe())), "..", "..", "..", "lib")]
sys.path[0:0] = [os.path.join(os.path.dirname(inspect.getabsfile(inspect.currentframe())), "..")]

from kid import Kid

tom = Kid("Tom")
becky = Kid("Becky", tom)
dick = Kid("Dick", becky)
jane = Kid("Jane", dick)
harry = Kid("Harry", jane)
sally = Kid("Sally", harry)

phrase = "his mom locked her keys in the car, " + "so he should get a ride home with Hector"

print "Teacher:", phrase
sally.whisper(phrase)
heard = sally.ask()
print "Teacher heard:", heard
示例#10
0
文件: run.py 项目: dramatis/dramatis
#!/usr/bin/env python

import inspect
import sys
import os.path

sys.path[0:0] = [ os.path.join( os.path.dirname( inspect.getabsfile( inspect.currentframe() ) ), '..', '..', '..', 'lib' ) ]
sys.path[0:0] = [ os.path.join( os.path.dirname( inspect.getabsfile( inspect.currentframe() ) ), '..' ) ]

from kid import Kid

tom = Kid( "Tom" )
becky = Kid( "Becky", tom )
dick = Kid( "Dick", becky )
jane = Kid( "Jane", dick )
harry = Kid( "Harry", jane )
sally = Kid( "Sally", harry )

phrase = "his mom locked her keys in the car, " + \
         "so he should get a ride home with Hector"

print "Teacher:", phrase
heard = sally.whisper( phrase )
print "Teacher heard:", heard