Esempio n. 1
0
    def test_load_and_save(self):
        """load() and save() interface tests."""
        # Save and load the deck.
        with tempfile.NamedTemporaryFile(mode='w', newline='') as tf:
            self.deck.save(tf.name, overwrite=True)
            saved_deck = Deck.load(tf.name)

        # Test.
        self.assertEqual(saved_deck, self.deck)
Esempio n. 2
0
def swap(args):
    """Swap-create a new flashcard deck.

    Create a new flashcard deck by swapping questions and answers.

    Args:
        args (argparse.Namespace): command line arguments.
    """
    print('Swapping questions and answers from {} and saving to {}.'.format(
        args.deck, args.dest))
    src = Deck.load(args.deck)
    dest = Deck(src.name)
    for c in src:
        dest.add_card(Flashcard(c.answer, c.question))

    dest.save(args.dest)
Esempio n. 3
0
    def test_sample_deck_file(self):
        """Load sample deck from README.md test."""
        sample = """Name: Sample Deck
Quiz:
Question,Answer,Attempts,Correct,Last Shown
1 + 1, 2
1 + 2, 3
1 + 3, 4
1 + 4, 5
1 + 5, 6
1 + 6, 7
1 + 7, 8
1 + 8, 9
1 + 9, 10
"""
        with tempfile.NamedTemporaryFile(mode='w', newline='') as tf:
            with open(tf.name, 'w') as f:
                f.write(sample)

            saved_deck = Deck.load(tf.name)
            self.assertEqual(saved_deck.name, 'Sample Deck')
            self.assertEqual(len(saved_deck), 9)
Esempio n. 4
0
    def __init__(self, deck, hard_weight=1, medium_weight=1, easy_weight=1):
        """
        Args:
            deck (str): Path to deck file.
            hard_weight (int): Favor (with respect to other weights) to give to
                hard flashcards.
            medium_weight (int): Favor (with respect to other weights) to give
                to medium flashcards.
            easy_weight (int): Favor (with respect to other weights) to give to
                easy flashcards.
        """
        self._hard_correct_percentage = 0.75
        self._medium_correct_percentage = 0.90

        self._hard_correct_answers = 5
        self._medium_correct_answers = 10

        self._deck_name = deck
        self._deck = Deck.load(deck)
        self._decks = Sorted(*self._sort_deck(self._deck))
        self._weights = Sorted(hard_weight, medium_weight, easy_weight)
        self._attempts = 0
        self._correct = 0