def test_song(): expected = dedent(""" This is the house that Jack built. This is the malt That lay in the house that Jack built. This is the rat, That ate the malt That lay in the house that Jack built. This is the cat, That killed the rat, That ate the malt That lay in the house that Jack built. This is the dog, That worried the cat, That killed the rat, That ate the malt That lay in the house that Jack built. This is the cow with the crumpled horn, That tossed the dog, That worried the cat, That killed the rat, That ate the malt That lay in the house that Jack built. This is the maiden all forlorn, That milked the cow with the crumpled horn, That tossed the dog, That worried the cat, That killed the rat, That ate the malt That lay in the house that Jack built. This is the man all tattered and torn, That kissed the maiden all forlorn, That milked the cow with the crumpled horn, That tossed the dog, That worried the cat, That killed the rat, That ate the malt That lay in the house that Jack built. This is the priest all shaven and shorn, That married the man all tattered and torn, That kissed the maiden all forlorn, That milked the cow with the crumpled horn, That tossed the dog, That worried the cat, That killed the rat, That ate the malt That lay in the house that Jack built. This is the rooster that crow'd in the morn, That waked the priest all shaven and shorn, That married the man all tattered and torn, That kissed the maiden all forlorn, That milked the cow with the crumpled horn, That tossed the dog, That worried the cat, That killed the rat, That ate the malt That lay in the house that Jack built. This is the farmer sowing his corn, That kept the rooster that crow'd in the morn, That waked the priest all shaven and shorn, That married the man all tattered and torn, That kissed the maiden all forlorn, That milked the cow with the crumpled horn, That tossed the dog, That worried the cat, That killed the rat, That ate the malt That lay in the house that Jack built. This is the horse and the hound and the horn, That belong to the farmer sowing his corn, That kept the rooster that crow'd in the morn, That waked the priest all shaven and shorn, That married the man all tattered and torn, That kissed the maiden all forlorn, That milked the cow with the crumpled horn, That tossed the dog, That worried the cat, That killed the rat, That ate the malt That lay in the house that Jack built.""") expect(song()).to_equal(expected)
def test_reversed_song(): expected = dedent(""" .tliub kcaJ taht esuoh eht si sihT .tliub kcaJ taht esuoh eht ni yal tahT tlam eht si sihT .tliub kcaJ taht esuoh eht ni yal tahT tlam eht eta tahT ,tar eht si sihT .tliub kcaJ taht esuoh eht ni yal tahT tlam eht eta tahT ,tar eht dellik tahT ,tac eht si sihT .tliub kcaJ taht esuoh eht ni yal tahT tlam eht eta tahT ,tar eht dellik tahT ,tac eht deirrow tahT ,god eht si sihT .tliub kcaJ taht esuoh eht ni yal tahT tlam eht eta tahT ,tar eht dellik tahT ,tac eht deirrow tahT ,god eht dessot tahT ,nroh delpmurc eht htiw woc eht si sihT .tliub kcaJ taht esuoh eht ni yal tahT tlam eht eta tahT ,tar eht dellik tahT ,tac eht deirrow tahT ,god eht dessot tahT ,nroh delpmurc eht htiw woc eht deklim tahT ,nrolrof lla nediam eht si sihT .tliub kcaJ taht esuoh eht ni yal tahT tlam eht eta tahT ,tar eht dellik tahT ,tac eht deirrow tahT ,god eht dessot tahT ,nroh delpmurc eht htiw woc eht deklim tahT ,nrolrof lla nediam eht dessik tahT ,nrot dna derettat lla nam eht si sihT .tliub kcaJ taht esuoh eht ni yal tahT tlam eht eta tahT ,tar eht dellik tahT ,tac eht deirrow tahT ,god eht dessot tahT ,nroh delpmurc eht htiw woc eht deklim tahT ,nrolrof lla nediam eht dessik tahT ,nrot dna derettat lla nam eht deirram tahT ,nrohs dna nevahs lla tseirp eht si sihT .tliub kcaJ taht esuoh eht ni yal tahT tlam eht eta tahT ,tar eht dellik tahT ,tac eht deirrow tahT ,god eht dessot tahT ,nroh delpmurc eht htiw woc eht deklim tahT ,nrolrof lla nediam eht dessik tahT ,nrot dna derettat lla nam eht deirram tahT ,nrohs dna nevahs lla tseirp eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht si sihT .tliub kcaJ taht esuoh eht ni yal tahT tlam eht eta tahT ,tar eht dellik tahT ,tac eht deirrow tahT ,god eht dessot tahT ,nroh delpmurc eht htiw woc eht deklim tahT ,nrolrof lla nediam eht dessik tahT ,nrot dna derettat lla nam eht deirram tahT ,nrohs dna nevahs lla tseirp eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht tpek tahT ,nroc sih gniwos remraf eht si sihT .tliub kcaJ taht esuoh eht ni yal tahT tlam eht eta tahT ,tar eht dellik tahT ,tac eht deirrow tahT ,god eht dessot tahT ,nroh delpmurc eht htiw woc eht deklim tahT ,nrolrof lla nediam eht dessik tahT ,nrot dna derettat lla nam eht deirram tahT ,nrohs dna nevahs lla tseirp eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht tpek tahT ,nroc sih gniwos remraf eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht si sihT""") expect(song(reverse=True)).to_equal(expected)
def test_random_double_reversed_song(): expected = dedent(""" .deirrow tahT ,god eht deirrow tahT ,god eht si sihT .deirrow tahT ,god eht deirrow tahT ,god eht tpek tahT ,nroc sih gniwos remraf eht tpek tahT ,nroc sih gniwos remraf eht si sihT .deirrow tahT ,god eht deirrow tahT ,god eht tpek tahT ,nroc sih gniwos remraf eht tpek tahT ,nroc sih gniwos remraf eht dessot tahT ,nroh delpmurc eht htiw woc eht dessot tahT ,nroh delpmurc eht htiw woc eht si sihT .deirrow tahT ,god eht deirrow tahT ,god eht tpek tahT ,nroc sih gniwos remraf eht tpek tahT ,nroc sih gniwos remraf eht dessot tahT ,nroh delpmurc eht htiw woc eht dessot tahT ,nroh delpmurc eht htiw woc eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht si sihT .deirrow tahT ,god eht deirrow tahT ,god eht tpek tahT ,nroc sih gniwos remraf eht tpek tahT ,nroc sih gniwos remraf eht dessot tahT ,nroh delpmurc eht htiw woc eht dessot tahT ,nroh delpmurc eht htiw woc eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ni yal tahT tlam eht ni yal tahT tlam eht si sihT .deirrow tahT ,god eht deirrow tahT ,god eht tpek tahT ,nroc sih gniwos remraf eht tpek tahT ,nroc sih gniwos remraf eht dessot tahT ,nroh delpmurc eht htiw woc eht dessot tahT ,nroh delpmurc eht htiw woc eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ni yal tahT tlam eht ni yal tahT tlam eht dellik tahT ,tac eht dellik tahT ,tac eht si sihT .deirrow tahT ,god eht deirrow tahT ,god eht tpek tahT ,nroc sih gniwos remraf eht tpek tahT ,nroc sih gniwos remraf eht dessot tahT ,nroh delpmurc eht htiw woc eht dessot tahT ,nroh delpmurc eht htiw woc eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ni yal tahT tlam eht ni yal tahT tlam eht dellik tahT ,tac eht dellik tahT ,tac eht deirram tahT ,nrohs dna nevahs lla tseirp eht deirram tahT ,nrohs dna nevahs lla tseirp eht si sihT .deirrow tahT ,god eht deirrow tahT ,god eht tpek tahT ,nroc sih gniwos remraf eht tpek tahT ,nroc sih gniwos remraf eht dessot tahT ,nroh delpmurc eht htiw woc eht dessot tahT ,nroh delpmurc eht htiw woc eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ni yal tahT tlam eht ni yal tahT tlam eht dellik tahT ,tac eht dellik tahT ,tac eht deirram tahT ,nrohs dna nevahs lla tseirp eht deirram tahT ,nrohs dna nevahs lla tseirp eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht si sihT .deirrow tahT ,god eht deirrow tahT ,god eht tpek tahT ,nroc sih gniwos remraf eht tpek tahT ,nroc sih gniwos remraf eht dessot tahT ,nroh delpmurc eht htiw woc eht dessot tahT ,nroh delpmurc eht htiw woc eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ni yal tahT tlam eht ni yal tahT tlam eht dellik tahT ,tac eht dellik tahT ,tac eht deirram tahT ,nrohs dna nevahs lla tseirp eht deirram tahT ,nrohs dna nevahs lla tseirp eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht eta tahT ,tar eht eta tahT ,tar eht si sihT .deirrow tahT ,god eht deirrow tahT ,god eht tpek tahT ,nroc sih gniwos remraf eht tpek tahT ,nroc sih gniwos remraf eht dessot tahT ,nroh delpmurc eht htiw woc eht dessot tahT ,nroh delpmurc eht htiw woc eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ni yal tahT tlam eht ni yal tahT tlam eht dellik tahT ,tac eht dellik tahT ,tac eht deirram tahT ,nrohs dna nevahs lla tseirp eht deirram tahT ,nrohs dna nevahs lla tseirp eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht eta tahT ,tar eht eta tahT ,tar eht dessik tahT ,nrot dna derettat lla nam eht dessik tahT ,nrot dna derettat lla nam eht si sihT .deirrow tahT ,god eht deirrow tahT ,god eht tpek tahT ,nroc sih gniwos remraf eht tpek tahT ,nroc sih gniwos remraf eht dessot tahT ,nroh delpmurc eht htiw woc eht dessot tahT ,nroh delpmurc eht htiw woc eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ni yal tahT tlam eht ni yal tahT tlam eht dellik tahT ,tac eht dellik tahT ,tac eht deirram tahT ,nrohs dna nevahs lla tseirp eht deirram tahT ,nrohs dna nevahs lla tseirp eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht eta tahT ,tar eht eta tahT ,tar eht dessik tahT ,nrot dna derettat lla nam eht dessik tahT ,nrot dna derettat lla nam eht deklim tahT ,nrolrof lla nediam eht deklim tahT ,nrolrof lla nediam eht si sihT .deirrow tahT ,god eht deirrow tahT ,god eht tpek tahT ,nroc sih gniwos remraf eht tpek tahT ,nroc sih gniwos remraf eht dessot tahT ,nroh delpmurc eht htiw woc eht dessot tahT ,nroh delpmurc eht htiw woc eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ot gnoleb tahT ,nroh eht dna dnuoh eht dna esroh eht ni yal tahT tlam eht ni yal tahT tlam eht dellik tahT ,tac eht dellik tahT ,tac eht deirram tahT ,nrohs dna nevahs lla tseirp eht deirram tahT ,nrohs dna nevahs lla tseirp eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht dekaw tahT ,nrom eht ni d'worc taht retsoor eht eta tahT ,tar eht eta tahT ,tar eht dessik tahT ,nrot dna derettat lla nam eht dessik tahT ,nrot dna derettat lla nam eht deklim tahT ,nrolrof lla nediam eht deklim tahT ,nrolrof lla nediam eht tliub kcaJ taht esuoh eht tliub kcaJ taht esuoh eht si sihT""" ) global index index = 0 rndint = random.randint random.randint = randint_patched expect(song(rnd=True, double=True, reverse=True)).to_equal(expected) random.randint = rndint
def test_double_random_song(): expected = dedent(""" This is the dog, That worried the dog, That worried. This is the farmer sowing his corn, That kept the farmer sowing his corn, That kept the dog, That worried the dog, That worried. This is the cow with the crumpled horn, That tossed the cow with the crumpled horn, That tossed the farmer sowing his corn, That kept the farmer sowing his corn, That kept the dog, That worried the dog, That worried. This is the horse and the hound and the horn, That belong to the horse and the hound and the horn, That belong to the cow with the crumpled horn, That tossed the cow with the crumpled horn, That tossed the farmer sowing his corn, That kept the farmer sowing his corn, That kept the dog, That worried the dog, That worried. This is the malt That lay in the malt That lay in the horse and the hound and the horn, That belong to the horse and the hound and the horn, That belong to the cow with the crumpled horn, That tossed the cow with the crumpled horn, That tossed the farmer sowing his corn, That kept the farmer sowing his corn, That kept the dog, That worried the dog, That worried. This is the cat, That killed the cat, That killed the malt That lay in the malt That lay in the horse and the hound and the horn, That belong to the horse and the hound and the horn, That belong to the cow with the crumpled horn, That tossed the cow with the crumpled horn, That tossed the farmer sowing his corn, That kept the farmer sowing his corn, That kept the dog, That worried the dog, That worried. This is the priest all shaven and shorn, That married the priest all shaven and shorn, That married the cat, That killed the cat, That killed the malt That lay in the malt That lay in the horse and the hound and the horn, That belong to the horse and the hound and the horn, That belong to the cow with the crumpled horn, That tossed the cow with the crumpled horn, That tossed the farmer sowing his corn, That kept the farmer sowing his corn, That kept the dog, That worried the dog, That worried. This is the rooster that crow'd in the morn, That waked the rooster that crow'd in the morn, That waked the priest all shaven and shorn, That married the priest all shaven and shorn, That married the cat, That killed the cat, That killed the malt That lay in the malt That lay in the horse and the hound and the horn, That belong to the horse and the hound and the horn, That belong to the cow with the crumpled horn, That tossed the cow with the crumpled horn, That tossed the farmer sowing his corn, That kept the farmer sowing his corn, That kept the dog, That worried the dog, That worried. This is the rat, That ate the rat, That ate the rooster that crow'd in the morn, That waked the rooster that crow'd in the morn, That waked the priest all shaven and shorn, That married the priest all shaven and shorn, That married the cat, That killed the cat, That killed the malt That lay in the malt That lay in the horse and the hound and the horn, That belong to the horse and the hound and the horn, That belong to the cow with the crumpled horn, That tossed the cow with the crumpled horn, That tossed the farmer sowing his corn, That kept the farmer sowing his corn, That kept the dog, That worried the dog, That worried. This is the man all tattered and torn, That kissed the man all tattered and torn, That kissed the rat, That ate the rat, That ate the rooster that crow'd in the morn, That waked the rooster that crow'd in the morn, That waked the priest all shaven and shorn, That married the priest all shaven and shorn, That married the cat, That killed the cat, That killed the malt That lay in the malt That lay in the horse and the hound and the horn, That belong to the horse and the hound and the horn, That belong to the cow with the crumpled horn, That tossed the cow with the crumpled horn, That tossed the farmer sowing his corn, That kept the farmer sowing his corn, That kept the dog, That worried the dog, That worried. This is the maiden all forlorn, That milked the maiden all forlorn, That milked the man all tattered and torn, That kissed the man all tattered and torn, That kissed the rat, That ate the rat, That ate the rooster that crow'd in the morn, That waked the rooster that crow'd in the morn, That waked the priest all shaven and shorn, That married the priest all shaven and shorn, That married the cat, That killed the cat, That killed the malt That lay in the malt That lay in the horse and the hound and the horn, That belong to the horse and the hound and the horn, That belong to the cow with the crumpled horn, That tossed the cow with the crumpled horn, That tossed the farmer sowing his corn, That kept the farmer sowing his corn, That kept the dog, That worried the dog, That worried. This is the house that Jack built the house that Jack built the maiden all forlorn, That milked the maiden all forlorn, That milked the man all tattered and torn, That kissed the man all tattered and torn, That kissed the rat, That ate the rat, That ate the rooster that crow'd in the morn, That waked the rooster that crow'd in the morn, That waked the priest all shaven and shorn, That married the priest all shaven and shorn, That married the cat, That killed the cat, That killed the malt That lay in the malt That lay in the horse and the hound and the horn, That belong to the horse and the hound and the horn, That belong to the cow with the crumpled horn, That tossed the cow with the crumpled horn, That tossed the farmer sowing his corn, That kept the farmer sowing his corn, That kept the dog, That worried the dog, That worried.""") global index index = 0 rint = random.randint random.randint = randint_patched expect(song(rnd=True, double=True)).to_equal(expected) random.randint = rint