diff --git a/exercises/concept/elyses-enchantments/.docs/hints.md b/exercises/concept/card-games/.docs/hints.md similarity index 55% rename from exercises/concept/elyses-enchantments/.docs/hints.md rename to exercises/concept/card-games/.docs/hints.md index a9c4c900ea..0920ce9a90 100644 --- a/exercises/concept/elyses-enchantments/.docs/hints.md +++ b/exercises/concept/card-games/.docs/hints.md @@ -2,54 +2,42 @@ ## General -## 1. Creating a List +## 1. Tracking Poker Rounds - `Lists` in python may be [constructed](https://docs.python.org/3/library/stdtypes.html#list) in several ways. - This function should [return](https://www.w3schools.com/python/ref_keyword_return.asp) a `list`. -## 2. Creating a copy of a List - -- `Lists` can be [nested](https://realpython.com/python-lists-tuples/#lists-can-be-nested), this means that a `list` can be an element of another `list`. -- This function should [return](https://www.w3schools.com/python/ref_keyword_return.asp) a `list` containing two `lists`. - -## 3. Concatenating Lists +## 2. Keeping all Rounds in the Same Place - Sequence types such as `list` already support a few [common operations](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) - This function should [return](https://www.w3schools.com/python/ref_keyword_return.asp) a `list`. -## 4. Testing List Membership +## 3. Finding Prior Rounds - Sequence types such as `list` already support a few [common operations](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) - This function should [return](https://www.w3schools.com/python/ref_keyword_return.asp) a `boolean`. -## 5. Accessing List Elements by Index +## 4. Averaging Card Values + +- There are a few techniques to [iterate over a `list` in python](https://www.geeksforgeeks.org/iterate-over-a-list-in-python/). +- To get the average, this function should count how many items are in the list and sum up their values. Then, return sum divided by count. + +## 5. Alternate Averages - Sequence types such as `list` already support a few [common operations](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) - To access an element use the square brackets notation. - Remember that the first element of the `list` is at index 0 - In python, negative indexing starts the count from the end. This mean that you can find the last element of the `list` at index -1. -- This function should [return](https://www.w3schools.com/python/ref_keyword_return.asp) a `list` containing two elements. +- Think about reusing the code from the functions that you just implemented. -## 6. Accessing Sublists by Slicing +## 6. More Averaging Techniques - Sequence types such as `list` already support a few [common operations](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) -- For the last part of the exercise, think about reusing the code from the functions that you just implemented. -- These functions should [return](https://www.w3schools.com/python/ref_keyword_return.asp) a `list`. +- Think about reusing the code from the functions that you just implemented. +- The slice syntax supports a step value. -## 7. Iterating Over List Items - -- There are a few techniques to [iterate over a `list` in python](https://www.geeksforgeeks.org/iterate-over-a-list-in-python/). -- You should use the function `print` on each element of the `list` to print each of them on a separate line. -- This function should not [return](https://www.w3schools.com/python/ref_keyword_return.asp) anything so you should end it with just the statement `return`. - -## 8. Creating Lists with Mixed Data Types - -- There are many [built-in types](https://docs.python.org/3/library/stdtypes.html) in python. -- [`Lists` Can Contain Arbitrary Objects](https://realpython.com/python-lists-tuples/#lists-can-contain-arbitrary-objects). -- This function should [return](https://www.w3schools.com/python/ref_keyword_return.asp) a `list`. - -## 9. Modifying Values in Lists +## 7. Bonus Round Rules - `Lists` in python are mutable, this means that once a `list` is created, you can modify, delete or add any element as you wish. - Python provides a wide range of [ways to modify `lists`](https://realpython.com/python-lists-tuples/#lists-are-mutable). -- This function should not [return](https://www.w3schools.com/python/ref_keyword_return.asp) anything so you should end it with the statement `return` alone. +- This function should not [return](https://www.w3schools.com/python/ref_keyword_return.asp) anything so you should end it with just the statement `return`. diff --git a/exercises/concept/card-games/.docs/instructions.md b/exercises/concept/card-games/.docs/instructions.md new file mode 100644 index 0000000000..8830cb9791 --- /dev/null +++ b/exercises/concept/card-games/.docs/instructions.md @@ -0,0 +1,101 @@ +# Instructions + +## Instructions + +Elyse is really looking forward to playing some poker (and other card games) during her upcoming trip to Vegas. Being a big fan of "self-tracking" she wants to put together some small functions that will help her with tracking tasks and has asked for your help thinking them through. + +## 1. Tracking Poker Rounds + +Elyse is especially fond of poker, and wants to track how many rounds she plays - and _which rounds_ those are. Every round has its own number, and every table shows the round number currently being played. Elyse chooses a table and sits down to play her first round. She plans on playing three rounds. + +Implement a function `to_rounds` that takes the current round number and returns a single list with that round and the _next two_ that are coming up: + +```python +>>> to_rounds(27) +[27, 28, 29] +``` + +## 2. Keeping all Rounds in the Same Place + +Elyse played a few rounds at the first table, then took a break and played some more rounds at a second table ... but ended up with a different list for each table! She wants to put the two lists together, so she can track all of the poker rounds in the same place. + +Implement a function `concatenate_rounds` that takes two lists and returns a single list consisting of all the rounds in the first list, followed by all the rounds in the second list: + +```python +>>> concatenate_rounds([27, 28, 29], [35, 36]) +[27, 28, 29, 35, 36] +``` + +## 3. Finding Prior Rounds + +Talking about some of the prior Poker rounds, another player remarks how similarly two of them played out. Elyse is not sure if she played those rounds or not. + +Implement a function `list_contains_round` that takes two arguments, a list of rounds played and a round number. The function will return `True` if the round is in the list of rounds played, `False` if not: + +```python +>>> list_contains_round([27, 28, 29, 35, 36], 29) +True + +>>> list_contains_round([27, 28, 29, 35, 36], 30) +False +``` + +## 4. Averaging Card Values + +Elyse wants to try out a new game called Black Joe. It's similar to Black Jack - where your goal is to have the cards in your hand add up to a target value - but in Black Joe the goal is to get the _average_ of the card values to be 7. The average can be found by summing up all the card values and then dividing that sum by the number of cards in the hand. + +Implement a function `card_average` that will return the average value of a hand of Black Joe. + +```python +>>> card_average([5, 6, 7]) +6.0 +``` + +## 5. Alternate Averages + +In Black Joe, speed is important. Elyse thinks she can "shortcut" the traditional calculation to get an _average-like_ number by taking the average of the first and last card values in the hand - or by using the "middle" card value (the median) of the hand. She's hoping one of these calculations might come close to the average, but be quicker to calculate during game play. She'd like you to create a function to test her theory out. + +Implement a function `approx_average_is_average` that returns a boolean, indicating if either of Elyse's approximation formulas is the same as calculating the "full" average of a hand. For the sake of a simple median, we are going to assume the hand always has an odd number of card values. + +```python +>>> approx_average_is_average([1, 2, 3]) +True + +>>> approx_average_is_average([2, 3, 4, 8, 8]) +True + +>>> approx_average_is_average([1, 2, 3, 5, 9]) +False +``` + +## 6. More Averaging Techniques + +Intrigued by the results of her averaging experiment, Elyse is wondering if taking the average of _even_ values versus the average of _odd_ values would give the same results. Time for another test function! + +Implement a function `average_even_is_average_odd` that returns a boolean indicating of the average of the even valued cards is the same as the average of the odd valued cards. + +```python +>>> average_even_is_average_odd([1, 2, 3]) +True + +>>> average_even_is_average_odd([1, 2, 3, 4]) +False +``` + +## 7. Bonus Round Rules + +Every 11th hand in Black Joe is a bonus hand with a bonus rule: if the last card you draw is a Jack, you double its value. + +Implement a function `maybe_double_last` that takes a hand and checks if the last card is a Jack (11). If the the last card is a Jack (11), double its value. + +```python +>>> hand = [5, 9, 11] +>>> maybe_double_last(hand) +>>> hand +[5, 9, 22] + +>>> hand = [5, 9, 10] +>>> maybe_double_last(hand) +>>> hand +[5, 9, 10] +``` diff --git a/exercises/concept/elyses-enchantments/.docs/introduction.md b/exercises/concept/card-games/.docs/introduction.md similarity index 100% rename from exercises/concept/elyses-enchantments/.docs/introduction.md rename to exercises/concept/card-games/.docs/introduction.md diff --git a/exercises/concept/elyses-enchantments/.meta/config.json b/exercises/concept/card-games/.meta/config.json similarity index 63% rename from exercises/concept/elyses-enchantments/.meta/config.json rename to exercises/concept/card-games/.meta/config.json index 9cf59a9029..1cff316f04 100644 --- a/exercises/concept/elyses-enchantments/.meta/config.json +++ b/exercises/concept/card-games/.meta/config.json @@ -1,11 +1,12 @@ { - "blurb": "Learn about lists by helping Elyse practice her playing card enchantments.", + "blurb": "Learn about lists by tracking hands in card games.", "contributors": [ - "valentin-p", - "bethanyg" + "valentin-p" ], "authors": [ - "itamargal" + "itamargal", + "isaacg", + "bethanyg" ], "files": { "solution": [ diff --git a/exercises/concept/elyses-enchantments/.meta/design.md b/exercises/concept/card-games/.meta/design.md similarity index 90% rename from exercises/concept/elyses-enchantments/.meta/design.md rename to exercises/concept/card-games/.meta/design.md index 7da8a9fdc3..6977ba5eaf 100644 --- a/exercises/concept/elyses-enchantments/.meta/design.md +++ b/exercises/concept/card-games/.meta/design.md @@ -8,11 +8,10 @@ The goal of this exercise is to teach the basics of the `list` data type in Pyth - Create a `list` via constructor (`list()`) & literal (`[]`) - Combine two or more lists by concatenation via `+` -- Check for an items membership/absence in a list using `in` and/or `not in` +- Check for an items membership/absence in a list using `in` - Access items in a list via index (`bracket notation`) - Access a range of items in a list via list slicing (`[start:stop:step]`) - Iterate through a list using `for item in` -- Understand that `lists` can store mixed/any data types - Understand that `lists` are mutable. Assigning a new value to a list index will change the value at that index. ## Out of scope diff --git a/exercises/concept/card-games/.meta/exemplar.py b/exercises/concept/card-games/.meta/exemplar.py new file mode 100644 index 0000000000..cef81a3b8e --- /dev/null +++ b/exercises/concept/card-games/.meta/exemplar.py @@ -0,0 +1,39 @@ +def to_rounds(number): + """Return a list of rounds that includes `number` and the next two.""" + return [number, number + 1, number + 2] + + +def concatenate_rounds(rounds1, rounds2): + """Return a list of rounds that combines `rounds1` and `rounds2`.""" + return rounds1 + rounds2 + + +def list_contains_round(rounds, number): + """Return whether `rounds` includes the `number` round.""" + return number in rounds + + +def card_average(hand): + """Return the average of the hand.""" + total = 0 + count = 0 + for card in hand: + total += card + count += 1 + return total / count + + +def approx_average_is_average(hand): + """Return whether the average of the first and last card is the average.""" + return card_average([hand[0], hand[-1]]) == card_average(hand) + + +def average_even_is_average_odd(hand): + """Return whether the average of the even cards is the same as that odd cards.""" + return card_average(hand[::2]) == card_average(hand[1::2]) + + +def maybe_double_last(hand): + """Double the value of the last card if it is a Jack (11).""" + if hand[-1] == 11: + hand[-1] *= 2 diff --git a/exercises/concept/card-games/lists.py b/exercises/concept/card-games/lists.py new file mode 100644 index 0000000000..58b4633038 --- /dev/null +++ b/exercises/concept/card-games/lists.py @@ -0,0 +1,33 @@ +def to_rounds(number): + """Return a list of rounds that includes `number` and the next two.""" + pass + + +def concatenate_rounds(rounds1, rounds2): + """Return a list of rounds that combines `rounds1` and `rounds2`.""" + pass + + +def list_contains_round(rounds, number): + """Return whether `rounds` includes the `number` round.""" + pass + + +def card_average(hand): + """Return the average of the hand.""" + pass + + +def approx_average_is_average(hand): + """Return whether the average of the first and last card is the average.""" + pass + + +def average_even_is_average_odd(hand): + """Return whether the average of the even cards is the same as that odd cards.""" + pass + + +def maybe_double_last(hand): + """Double the value of the last card if it is a Jack (11).""" + pass diff --git a/exercises/concept/card-games/lists_test.py b/exercises/concept/card-games/lists_test.py new file mode 100644 index 0000000000..2a72019abd --- /dev/null +++ b/exercises/concept/card-games/lists_test.py @@ -0,0 +1,327 @@ +import unittest +import random +from lists import ( + to_rounds, + concatenate_rounds, + list_contains_round, + card_average, + approx_average_is_average, + average_even_is_average_odd, + maybe_double_last, +) + + +class TestToRounds(unittest.TestCase): + + def test_instructions_example(self): + round_number = 27 + want = [27, 28, 29] + got = to_rounds(round_number) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_zero(self): + round_number = 0 + want = [0, 1, 2] + got = to_rounds(round_number) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_random_int(self): + round_number = random.randint(0, 100) + want = [round_number + i for i in range(3)] + got = to_rounds(round_number) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + +class TestConcatenateRounds(unittest.TestCase): + + def test_instructions_example(self): + rounds1 = [27, 28, 29] + rounds2 = [35, 36] + want = [27, 28, 29, 35, 36] + got = concatenate_rounds(rounds1, rounds2) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_empty(self): + rounds1 = [] + rounds2 = [] + want = [] + got = concatenate_rounds(rounds1, rounds2) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_other(self): + rounds1 = [1, 2, 3] + rounds2 = [4, 5, 6] + want = [1, 2, 3, 4, 5, 6] + got = concatenate_rounds(rounds1, rounds2) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + +class TestListContainsRound(unittest.TestCase): + + def test_instructions_example_1(self): + rounds = [27, 28, 29, 35, 36] + round_number = 29 + want = True + got = list_contains_round(rounds, round_number) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_instructions_example_2(self): + rounds = [27, 28, 29, 35, 36] + round_number = 30 + want = False + got = list_contains_round(rounds, round_number) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_empty(self): + rounds = [] + round_number = 1 + want = False + got = list_contains_round(rounds, round_number) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_other_true(self): + rounds = [1, 2, 3] + round_number = 2 + want = True + got = list_contains_round(rounds, round_number) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_other_false(self): + rounds = [1, 2, 3] + round_number = 0 + want = False + got = list_contains_round(rounds, round_number) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + +class TestCardAverage(unittest.TestCase): + + def test_instructions_example(self): + hand = [5, 6, 7] + want = 6.0 + got = card_average(hand) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_other(self): + hand = [1, 2, 3, 4] + want = 2.5 + got = card_average(hand) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + + +class TestApproxAverageIsAverage(unittest.TestCase): + + def test_instructions_example_1(self): + hand = [1, 2, 3] + want = True + got = approx_average_is_average(hand) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_instructions_example_2(self): + hand = [2, 3, 4, 8, 8] + want = True + got = approx_average_is_average(hand) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_instructions_example_3(self): + hand = [1, 2, 3, 5, 9] + want = False + got = approx_average_is_average(hand) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_other_true(self): + hand = [2, 3, 4] + want = True + got = approx_average_is_average(hand) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_other_false(self): + hand = [2, 3, 4, 7] + want = False + got = approx_average_is_average(hand) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + +class TestAverageEvenIsAverageOdd(unittest.TestCase): + + def test_instructions_example_1(self): + hand = [1, 2, 3] + want = True + got = average_even_is_average_odd(hand) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_instructions_example_2(self): + hand = [1, 2, 3, 4] + want = False + got = average_even_is_average_odd(hand) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_other_true(self): + hand = [5, 6, 7] + want = True + got = average_even_is_average_odd(hand) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + def test_other_false(self): + hand = [5, 6, 8] + want = False + got = average_even_is_average_odd(hand) + + self.assertEqual( + want, + got, + msg=f'Expected {want} but got an incorrect result: {got!r}' + ) + + +class TestMaybeDoubleLast(unittest.TestCase): + + def test_instructions_example_1(self): + hand = [5, 9, 11] + want = [5, 9, 22] + maybe_double_last(hand) + + self.assertEqual( + hand, + want, + msg=f'Expected {want} but got an incorrect result: {hand!r}' + ) + + def test_instructions_example_2(self): + hand = [5, 9, 10] + want = [5, 9, 10] + maybe_double_last(hand) + + self.assertEqual( + hand, + want, + msg=f'Expected {want} but got an incorrect result: {hand!r}' + ) + + def test_other_doubles(self): + hand = [1, 2, 11] + want = [1, 2, 22] + maybe_double_last(hand) + + self.assertEqual( + hand, + want, + msg=f'Expected {want} but got an incorrect result: {hand!r}' + ) + + def test_other_no_change(self): + hand = [1, 2, 3] + want = [1, 2, 3] + maybe_double_last(hand) + + self.assertEqual( + hand, + want, + msg=f'Expected {want} but got an incorrect result: {hand!r}' + ) diff --git a/exercises/concept/elyses-enchantments/.docs/instructions.md b/exercises/concept/elyses-enchantments/.docs/instructions.md deleted file mode 100644 index b51d759270..0000000000 --- a/exercises/concept/elyses-enchantments/.docs/instructions.md +++ /dev/null @@ -1,147 +0,0 @@ -# Instructions - -## Instructions - -As a magician-to-be, Elyse needs to practice some basics. She has a stack of cards that she wants to manipulate. In this exercise, we'll use lists to help Elyse perform her card tricks. - -## 1. Creating a List - -Some magic tricks involve forming a [hand](https://en.wikipedia.org/wiki/Glossary_of_card_game_terms#hand) as in a regular card game, e.g. forming a single hand from five individual cards. - -Implement a function `to_list` that takes five arguments and returns a single list with those arguments as its elements: - -```python ->>> to_list('10H', 'JH', 'QH', 'KH', 'AH') -['10H', 'JH', 'QH', 'KH', 'AH'] -``` - -## 2. Creating a copy of a List - -In a traditional deck of cards, each card is unique and only occurs once. But for some magic tricks, Elyse needs to sneak in duplicate copies of some cards. - -Implement a function `list_twice` that takes a single list as its only argument, and returns a list consisting of two copies of the list of cards in parameter: - -```python ->>> list_twice(['AC', 'AD', 'AH', 'AS']) -[['AC', 'AD', 'AH', 'AS'], ['AC', 'AD', 'AH', 'AS']] -``` - -## 3. Concatenating Lists - -For some tricks, Elyse needs to take two stacks of cards and put one on top of the other - -Implement a function `concatenate_lists` that takes two lists and returns a single list consisting of all the elements in the first list, followed by all the elements in the second list: - -```python ->>> concatenate_lists(['2C', '2H', '2D'], ['KC', 'KD']) -['2C', '2H', '2D', 'KC', 'KD'] -``` - -## 4. Testing List Membership - -Elyse is practicing one particular trick in which she has a volunteer select a set of cards from the deck, and she has to guess whether a certain card is in their hand. - -Implement a function `list_contains_object` that takes two arguments, an arbitrary object and a list, and returns `True` if the object is an element of the list: - -```python ->>> list_contains_object(['AC', 'AD', 'AH', 'AS'], 'AC') -True - ->>> list_contains_object(['AC', 'AD', 'AH', 'AS'], '10C') -False -``` - -## 5. Accessing List Elements by Index - -For some tricks, Elyse needs to be able to take cards from the top and bottom of the deck through a Sleight of hand. - -Implement a function `first_and_last` that returns the first and last elements from a list: - -```python ->>> first_and_last(['2C', '2H', '2D', 'KC', 'KD']) -['2C', 'KD'] -``` - -## 6. Accessing Sublists by Slicing - -For other tricks, Elyse needs to be able to pick cards in the middle of the deck of cards through a Sleight of hand. - -Implement a function `interior_of_list` that returns all elements of a list _except_ for the first and last elements: - -```python ->>> interior_of_list(['2C', '2H', '2D', 'KC', 'KD']) -['2H', '2D', 'KC'] -``` - -One of Elyse's most amazing tricks to reorder a shuffled deck. - -Implement a function `even_elements` that returns every element of even index from a list: - -```python ->>> even_elements(['2C', '2H', '2D', 'KC', 'KD']) -['2C', '2D', 'KD'] -``` - -Implement a function `odd_elements` that returns every element of odd index from a list: - -```python ->>> odd_elements(['2C', '2H', '2D', 'KC', 'KD']) -['2H', 'KC'] -``` - -Implement a function `unshuffle` that "unshuffles" a set of cards by appending the elements of odd index to the elements of even index: - -```python ->>> unshuffle(['2C', '2H', '2D', 'KC', 'KD']) -['2C', '2D', 'KD', '2H', 'KC'] -``` - -## 7. Iterating Over List Items - -For some tricks, Elyse guesses all the cards in a volunteer's hands and names them out loud. - -Implement a function `print_list` that prints each element of a list on a separate line: - -```python ->>> print_list(['2C', '2H', '2D', 'KC', 'KD']) -2C -2H -2D -KC -KD -``` - -## 8. Creating Lists with Mixed Data Types - -For some tricks, Elyse sneaks in objects that aren't even playing cards! - -Suppose that you're given a function `count_types` that returns a count of the number of distinct types that occur in a given list: - -```python ->>> count_types(['2C', '2H', '2D', 'KC', 'KD']) -1 ->>> count_types([1, 2, 3]) -1 ->>> count_types(['2C', '2H', '2D', 'KC', 'KD', 1, 2, 3]) -2 -``` - -Write a function `multitype_list` that returns a list of elements of at least three different types: - -```python ->>> count_types(multitype_list()) > 2 -True -``` - -## 9. Modifying Values in Lists - -For some tricks, Elyse needs to use sleight-of-hand to swap cards without anyone noticing. - -Implement a function `swap_first_and_last` that takes a list and swaps the positions of the first and last elements in the list: - -```python ->>> _list = ['2C', '2H', '2D', 'KC', 'KD'] ->>> swap_first_and_last(_list) ->>> _list -['KD', '2H', '2D', 'KC', '2C'] -``` diff --git a/exercises/concept/elyses-enchantments/.meta/exemplar.py b/exercises/concept/elyses-enchantments/.meta/exemplar.py deleted file mode 100644 index f88001e723..0000000000 --- a/exercises/concept/elyses-enchantments/.meta/exemplar.py +++ /dev/null @@ -1,47 +0,0 @@ -def to_list(arg1, arg2, arg3, arg4, arg5): - return [arg1, arg2, arg3, arg4, arg5] - - -def list_twice(cards): - return [cards, list(cards)] - - -def concatenate_lists(deck1, deck2): - return deck1 + deck2 - - -def list_contains_object(cards, card): - return card in cards - - -def first_and_last(cards): - return [cards[0], cards[-1]] - - -def interior_of_list(cards): - return cards[1:-1] - - -def even_elements(cards): - return cards[::2] - - -def odd_elements(cards): - return cards[1::2] - - -def unshuffle(cards): - return cards[::2] + cards[1::2] - - -def print_list(cards): - for card in cards: - print(card) - - -def multitype_list(): - return [1, '1', 1.0] - - -def swap_first_and_last(cards): - cards[0], cards[-1] = cards[-1], cards[0] diff --git a/exercises/concept/elyses-enchantments/lists.py b/exercises/concept/elyses-enchantments/lists.py deleted file mode 100644 index e16064e864..0000000000 --- a/exercises/concept/elyses-enchantments/lists.py +++ /dev/null @@ -1,46 +0,0 @@ -def to_list(arg1, arg2, arg3, arg4, arg5): - pass - - -def list_twice(cards): - pass - - -def concatenate_lists(deck1, deck2): - pass - - -def list_contains_object(cards, card): - pass - - -def first_and_last(cards): - pass - - -def interior_of_list(cards): - pass - - -def even_elements(cards): - pass - - -def odd_elements(cards): - pass - - -def unshuffle(cards): - pass - - -def print_list(cards): - pass - - -def multitype_list(): - pass - - -def swap_first_and_last(cards): - pass diff --git a/exercises/concept/elyses-enchantments/lists_test.py b/exercises/concept/elyses-enchantments/lists_test.py deleted file mode 100644 index 5e0b4c7d09..0000000000 --- a/exercises/concept/elyses-enchantments/lists_test.py +++ /dev/null @@ -1,231 +0,0 @@ -import unittest -import random -from io import StringIO -import sys -from lists import ( - to_list, - list_twice, - concatenate_lists, - list_contains_object, - first_and_last, - interior_of_list, - even_elements, - odd_elements, - unshuffle, - print_list, - multitype_list, - swap_first_and_last, -) - - -class CaptureOutput(list): - - def __enter__(self): - self._stdout = sys.stdout - sys.stdout = self._stringio = StringIO() - return self - - def __exit__(self, *args): - self.extend(self._stringio.getvalue().splitlines()) - del self._stringio - sys.stdout = self._stdout - - -class TestToList(unittest.TestCase): - - def test_instructions_example(self): - self.assertEqual( - to_list('10H', 'JH', 'QH', 'KH', 'AH'), - ['10H', 'JH', 'QH', 'KH', 'AH'] - ) - - def test_5_random_ints(self): - _list = [random.randint(0, 100) for _ in range(5)] - self.assertEqual(_list, to_list(*_list)) - - def test_too_few_args(self): - _list = [1, 2, 3, 4] - with self.assertRaises(TypeError): - to_list(*_list) - - def test_too_many_args(self): - _list = [1, 2, 3, 4, 5, 6] - with self.assertRaises(TypeError): - to_list(*_list) - - -class TestListTwice(unittest.TestCase): - - def test_instructions_example(self): - list1, list2 = list_twice(['AC', 'AD', 'AH', 'AS']) - self.assertEqual(list1, list2) - self.assertIsNot(list1, list2) - - def test_correct_values(self): - for i in range(5): - _list = [random.randint(0, 100) for _ in range(5)] - list1, list2 = list_twice(_list) - self.assertEqual(list1, list2) - - def test_distinct_objects(self): - for i in range(5): - _list = [random.randint(0, 100) for _ in range(5)] - list1, list2 = list_twice(_list) - self.assertIsNot(list1, list2) - - -class TestConcatenateLists(unittest.TestCase): - - def test_instructions_example(self): - self.assertEqual( - concatenate_lists(['2C', '2H', '2D'], ['KC', 'KD']), - ['2C', '2H', '2D', 'KC', 'KD'] - ) - - def test_empty_lists(self): - _list = [random.randint(0, 100) for _ in range(5)] - newlist = concatenate_lists(_list, []) - self.assertEqual(_list, newlist) - self.assertIsNot(_list, newlist) - - def test_lists_of_ints(self): - list1 = [ - random.randint(0, 100) for _ in range(1, random.randint(2, 100)) - ] - list2 = [ - random.randint(0, 100) for _ in range(1, random.randint(2, 100)) - ] - newlist = list1 + list2 - self.assertEqual(newlist, concatenate_lists(list1, list2)) - - -class TestListContainsObject(unittest.TestCase): - - def test_instructions_example_1(self): - self.assertTrue(list_contains_object(['AC', 'AD', 'AH', 'AS'], 'AC')) - - def test_instructions_example_2(self): - self.assertFalse(list_contains_object(['AC', 'AD', 'AH', 'AS'], '10C')) - - def test_random_ints(self): - _list = [ - random.randint(0, 100) for _ in range(1, random.randint(2, 100)) - ] - element = random.randint(0, 200) - _list_contains_object = (element in _list) - self.assertTrue( - list_contains_object(_list, element) == _list_contains_object - ) - - -class TestFirstAndLast(unittest.TestCase): - - def test_instructions_example(self): - self.assertEqual( - first_and_last(['2C', '2H', '2D', 'KC', 'KD']), - ['2C', 'KD'] - ) - - def test_random_ints(self): - _list = [ - random.randint(0, 100) for _ in range(1, random.randint(2, 100)) - ] - self.assertEqual(first_and_last(_list), [_list[0], _list[-1]]) - - -class InteriorOfList(unittest.TestCase): - - def test_instructions_example(self): - self.assertEqual( - interior_of_list(['2C', '2H', '2D', 'KC', 'KD']), - ['2H', '2D', 'KC'] - ) - - def test_random_ints(self): - _list = [ - random.randint(0, 100) for _ in range(1, random.randint(2, 100)) - ] - self.assertEqual(interior_of_list(_list), _list[1:-1]) - - -class TestEvenElements(unittest.TestCase): - - def test_instructions_example(self): - self.assertEqual( - even_elements(['2C', '2H', '2D', 'KC', 'KD']), - ['2C', '2D', 'KD'] - ) - - def test_random_ints(self): - _list = [ - random.randint(0, 100) for _ in range(1, random.randint(2, 100)) - ] - self.assertEqual(even_elements(_list), _list[::2]) - - -class OddElements(unittest.TestCase): - - def test_instructions_example(self): - self.assertEqual( - odd_elements(['2C', '2H', '2D', 'KC', 'KD']), - ['2H', 'KC'] - ) - - def test_random_ints(self): - _list = [ - random.randint(0, 100) for _ in range(1, random.randint(2, 100)) - ] - self.assertEqual(odd_elements(_list), _list[1::2]) - - -class Unshuffle(unittest.TestCase): - - def test_instructions_example(self): - self.assertEqual( - unshuffle(['2C', '2H', '2D', 'KC', 'KD']), - ['2C', '2D', 'KD', '2H', 'KC'] - ) - - def test_random_ints(self): - _list = [ - random.randint(0, 100) for _ in range(1, random.randint(2, 100)) - ] - self.assertEqual( - unshuffle(_list), - _list[::2] + _list[1::2] - ) - - -class PrintList(unittest.TestCase): - - def test_instructions_example(self): - with CaptureOutput() as output: - print_list(['2C', '2H', '2D', 'KC', 'KD']) - self.assertEqual( - output, - ["2C", "2H", "2D", "KC", "KD"] - ) - - def test_random_ints(self): - _list = [ - random.randint(0, 100) for _ in range(1, random.randint(2, 100)) - ] - with CaptureOutput() as output: - print_list(_list) - self.assertEqual([str(_) for _ in _list], output) - - -class MultitypeList(unittest.TestCase): - - def test_multitype_list(self): - print(multitype_list()) - self.assertTrue(len(set([type(_) for _ in multitype_list()])) >= 3) - - -class SwapFirstAndLast(unittest.TestCase): - - def test_instructions_example(self): - _list = ['2C', '2H', '2D', 'KC', 'KD'] - return_value = swap_first_and_last(_list) - self.assertIsNone(return_value) - self.assertEqual(_list, ['KD', '2H', '2D', 'KC', '2C'])