Ejemplo n.º 1
0
def test_3_of_a_kind_is_not_full_house():
    hand = Hand()
    hand.receive(Card(9, 'heart'))
    hand.receive(Card(9, 'club'))
    hand.receive(Card(9, 'spade'))
    hand.receive(Card(7, 'diamond'))
    hand.receive(Card(6, 'heart'))
    assert not is_full_house(hand)
Ejemplo n.º 2
0
def test_straight_starting_with_ace():
    hand = Hand()
    hand.receive(Card(14, 'heart'))
    hand.receive(Card(2, 'spade'))
    hand.receive(Card(3, 'club'))
    hand.receive(Card(4, 'diamond'))
    hand.receive(Card(5, 'heart'))
    assert is_straight(hand)
Ejemplo n.º 3
0
def test_royal_flush():
    hand = Hand()
    hand.receive(Card(14, 'heart'))
    hand.receive(Card(13, 'heart'))
    hand.receive(Card(12, 'heart'))
    hand.receive(Card(11, 'heart'))
    hand.receive(Card(10, 'heart'))
    assert is_royal_flush(hand)
Ejemplo n.º 4
0
def test_4_of_a_kind():
    hand = Hand()
    hand.receive(Card(9, 'heart'))
    hand.receive(Card(9, 'club'))
    hand.receive(Card(9, 'spade'))
    hand.receive(Card(9, 'diamond'))
    hand.receive(Card(8, 'heart'))
    assert is_4_of_a_kind(hand)
Ejemplo n.º 5
0
def test_flush():
    hand = Hand()
    hand.receive(Card(12, 'heart'))
    hand.receive(Card(10, 'heart'))
    hand.receive(Card(8, 'heart'))
    hand.receive(Card(6, 'heart'))
    hand.receive(Card(4, 'heart'))
    assert is_flush(hand)
Ejemplo n.º 6
0
def test_is_two_pair():
    hand = Hand()
    hand.receive(Card(9, 'heart'))
    hand.receive(Card(7, 'club'))
    hand.receive(Card(9, 'spade'))
    hand.receive(Card(7, 'diamond'))
    hand.receive(Card(8, 'heart'))
    assert is_two_pair(hand)
Ejemplo n.º 7
0
def test_is_straight():
    hand = Hand()
    hand.receive(Card(12, 'club'))
    hand.receive(Card(8, 'heart'))
    hand.receive(Card(8, 'spade'))
    hand.receive(Card(8, 'club'))
    hand.receive(Card(11, 'spade'))
    assert not is_straight(hand)
Ejemplo n.º 8
0
def test__is_not_straight():
    hand = Hand()
    hand.receive(Card(12, 'heart'))
    hand.receive(Card(11, 'spade'))
    hand.receive(Card(10, 'club'))
    hand.receive(Card(9, 'diamond'))
    hand.receive(Card(8, 'heart'))
    assert is_straight(hand)
Ejemplo n.º 9
0
def test_straight_flush():
    hand = Hand()
    hand.receive(Card(12, 'heart'))
    hand.receive(Card(11, 'heart'))
    hand.receive(Card(10, 'heart'))
    hand.receive(Card(9, 'heart'))
    hand.receive(Card(8, 'heart'))
    assert is_straight_flush(hand)
Ejemplo n.º 10
0
def test_full_house():
    hand = Hand()
    hand.receive(Card(9, 'heart'))
    hand.receive(Card(9, 'club'))
    hand.receive(Card(9, 'spade'))
    hand.receive(Card(7, 'diamond'))
    hand.receive(Card(7, 'heart'))
    assert is_full_house(hand)
Ejemplo n.º 11
0
def test_card_equality():
    card0 = Card(2, 'heart')
    card1 = Card(2, 'heart')
    card2 = Card(2, 'club')
    card3 = Card(3, 'heart')
    card4 = Card(3, 'club')

    assert card0 == card1
    assert card0 != card2
    assert card0 != card3
    assert card0 != card4
Ejemplo n.º 12
0
def test_nothing_is_nothing():
    hand = Hand()
    hand.receive(Card(12, 'heart'))
    hand.receive(Card(10, 'club'))
    hand.receive(Card(8, 'diamond'))
    hand.receive(Card(6, 'spade'))
    hand.receive(Card(4, 'heart'))
    for score in SCORES:
        if score.get('name', '') != 'nothing':
            assert not score['tester'](hand)
    assert is_nothing(hand)
Ejemplo n.º 13
0
    def get_cards_for_lesson(self, lesson, model):
        """This is a mess.  
        """

        cards = []
        for concept in lesson.concepts.all():
            card = Card.lookup_card(concept.id)
            cards.append(card)

        return cards
Ejemplo n.º 14
0
def jsoncard(request, card_id):
    """Renders JSON for a single card
    TODO: HTTP-cache these, since they're immutable
    (This is not actually used...)
    """

    model = get_model(request)
    card = Card.lookup_card(card_id)
    data = card.json()
    return HttpResponse(json.dumps(data), mimetype='text/plain')
Ejemplo n.º 15
0
    def get_cards_for_lesson(self,lesson,model):
        """This is a mess.  
        """

        cards = []
        for concept in lesson.concepts.all():
            card = Card.lookup_card(concept.id)
            cards.append(card)
            
        return cards
Ejemplo n.º 16
0
def jsoncard(request, card_id):
    """Renders JSON for a single card
    TODO: HTTP-cache these, since they're immutable
    (This is not actually used...)
    """

    model = get_model(request)
    card = Card.lookup_card(card_id)
    data = card.json()
    return HttpResponse(
                    json.dumps(data),
                    mimetype='text/plain'
                    )
Ejemplo n.º 17
0
    def log_impression(self,impression):
        logging.debug("Logging impression %s" % impression)

        self.seq_tick()
        # updates model_seq - must do this now since this is when the model gets persisted
        #TODO: fix encapsulation of seq_tick.  this is handled in base class.

        card = Card.lookup_card(impression.concept_id)
        next_status = self.get_next_card_status(card,impression.answer)
        logging.debug("Moving card to %s", next_status)
        self.move_card_to_pile(card,next_status)
        self.calculate_soonest(card)
    
        card.log_impression(impression)
Ejemplo n.º 18
0
def debug_card(request,card_id):
    card = Card.lookup_card(card_id)
    model = get_model(request)
    history = card.history()
    params = {}
    params['pile'] = model.which_pile(card)
    params['ert'] = safe_timedelta(seconds = model.get_ert(card))
    params['estimated_ert'] = safe_timedelta(model._estimate_ert(card))
    params['longest_yes'] = history.delay_on_longest_yes()
    params['most_recent_yes'] = history.delay_on_most_recent_yes()[0]
    params['how_far_back_most_recent_yes'] = history.delay_on_most_recent_yes()[1]
    params['next_exposure'] = model.next_exposure_date(card)
    params['last_exposure'] = history.lookup_last_impression()
    params['answer_history'] = history.full_impression_history(20)

    return render_to_response("deck/debug_card.html", params, 
            context_instance=RequestContext(request))
Ejemplo n.º 19
0
    def log_impression(self, impression):
        LearningModelBase.log_impression(self, impression)

        # print u"better decklogging %s" % impression
        card = Card.lookup_card(impression.concept_id)

        # if they got it right, do nothing
        if impression.answer == "Yes":
            # TODO: if impression time was long, move it up some
            return

        if impression.answer == "Discard":
            self.move_card_to_pile(card, "Discard")
            return

        if impression.answer == "No":
            # if they got it wrong, move that card near the front of the deck
            self.move_card_to_pile(card, "Active", self.how_far_back_when_wrong())
Ejemplo n.º 20
0
    def log_impression(self, impression):
        LearningModelBase.log_impression(self, impression)

        #print u"better decklogging %s" % impression
        card = Card.lookup_card(impression.concept_id)

        # if they got it right, do nothing
        if impression.answer == "Yes":
            #TODO: if impression time was long, move it up some
            return

        if impression.answer == "Discard":
            self.move_card_to_pile(card, 'Discard')
            return

        if impression.answer == "No":
            # if they got it wrong, move that card near the front of the deck
            self.move_card_to_pile(card, 'Active',
                                   self.how_far_back_when_wrong())
Ejemplo n.º 21
0
    def add_new_cards(self, describe_new_cards, card_id_list, pile=None):
        """Add a whole list of cards to the pile.
        Defaults to the get_default_new_pile() pile.
        Also requires a string describing the new cards.
        """

        # add to the description if there is one
        if self.description != "":
            self.description += ", "
            self.description += describe_new_cards
        else:
            self.description = describe_new_cards

        # figure out which pile to put them in
        if pile is None:
            pile = self.get_default_new_pile()

        # put them into the pile
        for id in card_id_list:
            card = Card.lookup_card(id)
            self._add_new_card(card, pile)
Ejemplo n.º 22
0
    def add_new_cards(self, describe_new_cards, card_id_list, pile=None):
        """Add a whole list of cards to the pile.
        Defaults to the get_default_new_pile() pile.
        Also requires a string describing the new cards.
        """

        # add to the description if there is one
        if self.description != "":
            self.description += ", "
            self.description += describe_new_cards
        else:
            self.description = describe_new_cards

        # figure out which pile to put them in
        if pile is None:
            pile = self.get_default_new_pile()

        # put them into the pile
        for id in card_id_list:
            card = Card.lookup_card(id)
            self._add_new_card(card, pile)
Ejemplo n.º 23
0
    def log_impression(self,impression):
        logging.debug(u"Logging impression %s" % impression)

        card = Card.lookup_card(impression.concept_id)
        card.log_impression(impression)
        self.seq_tick()

        history = card.history()
        previous_impression = history.lookup_earlier_impression(1)
        # If they don't differ we need to muck with the code.
        if previous_impression:
            current_delay = td_to_seconds(impression.answered_date - previous_impression.answered_date)
        else:
            current_delay = None
        logging.debug(u"Current delay is %s" % current_delay) # This might not work.
        current_answer = impression.answer
        if impression.answer == 'Discard':
            self.move_card_to_pile(card,'Discard')
        else:
            self.evaluate_card(card,current_delay,impression.answer)
            self.move_card_to_pile(card,'Learning')  # We're always learning all these.
Ejemplo n.º 24
0
def show_meta(request):
    # first, fetch the recent impressions
    recent_impressions = Impression.objects.order_by('-answered_date').filter(user=request.user)
    # limit to last 30 impressions
    recent_impressions = recent_impressions[0:29]

    # now build a list of card Q's, with the pile for each card. 
    # don't eliminate duplicate cards
    model = get_model(request)
    recent_cards = []
    for impression in recent_impressions:
        #print "id %s" % impression.concept.id
        card = Card.lookup_card(impression.concept.id)

        pile = model.which_pile(card)
        ert = model._get_card_metadata(card,'ert')  #TODO: Not portable!
        logging.debug("ert for %s is %s" % (card,ert))
        if ert:
            next_exposure = impression.answered_date + datetime.timedelta(seconds = ert)
        else:
            next_exposure = None
        recent_cards.append( (card.question(), pile, card, ert, next_exposure) )

    #
    # fetch counts for each pile
    #
    pilecount = []
    for pile in model.supported_piles():
        pilecount.append( (pile, len( model.cards_in_pile(pile) ) ) )

    # and the description
    description = model.description

    templatevars = {
        'recent_cards': recent_cards,
        'pilecount': pilecount,
        'description': description,
        }

    return render_to_response("deck/show_meta.html", templatevars)
Ejemplo n.º 25
0
def deckview(request):
    """Shows you a list of recent cards.
    """

    # first, fetch the recent impressions
    recent_impressions = Impression.objects.order_by('-answered_date').filter(user=request.user)
    # limit to last 30 impressions
    recent_impressions = recent_impressions[0:29]

    # now build a list of card Q's, with the pile for each card. 
    # don't eliminate duplicate cards
    model = get_model(request)
    recent_cards = []
    for impression in recent_impressions:
        #print "id %s" % impression.concept.id
        card = Card.lookup_card(impression.concept.id)

        pile = model.which_pile(card)
        recent_cards.append( (card.question(), pile, card) )

    #
    # fetch counts for each pile
    #
    pilecount = []
    for pile in model.supported_piles():
        pilecount.append( (pile, len( model.cards_in_pile(pile) ) ) )

    # and the description
    description = model.description

    templatevars = {
        'recent_cards': recent_cards,
        'pilecount': pilecount,
        'description': description,
        }

    return render_to_response("deck/deckview.html", templatevars)
Ejemplo n.º 26
0
    def log_impression(self, impression):
        logging.debug(u"Logging impression %s" % impression)

        card = Card.lookup_card(impression.concept_id)
        card.log_impression(impression)
        self.seq_tick()

        history = card.history()
        previous_impression = history.lookup_earlier_impression(1)
        # If they don't differ we need to muck with the code.
        if previous_impression:
            current_delay = td_to_seconds(impression.answered_date -
                                          previous_impression.answered_date)
        else:
            current_delay = None
        logging.debug(u"Current delay is %s" %
                      current_delay)  # This might not work.
        current_answer = impression.answer
        if impression.answer == 'Discard':
            self.move_card_to_pile(card, 'Discard')
        else:
            self.evaluate_card(card, current_delay, impression.answer)
            self.move_card_to_pile(
                card, 'Learning')  # We're always learning all these.
Ejemplo n.º 27
0
    def log_impression(self, impression):
        LearningModelBase.log_impression(self, impression)

        # here we need to actually rotate the card to the back.
        card = Card.lookup_card(impression.concept_id)
        self.move_card_to_pile(card, "Active")
Ejemplo n.º 28
0
 def init_cards(self):
     for suit in SUIT:
         for rank in range(2, 15):
             self.cards.append(Card(rank, suit))
Ejemplo n.º 29
0
    def log_impression(self, impression):
        LearningModelBase.log_impression(self, impression)

        # here we need to actually rotate the card to the back.
        card = Card.lookup_card(impression.concept_id)
        self.move_card_to_pile(card, 'Active')
Ejemplo n.º 30
0
def test_card_rank_setting():
    card = Card(3, 'heart')
    card.set_rank(2)
    assert 2 == card.get_rank()
Ejemplo n.º 31
0
def test_card_suit_setting():
    card = Card(2, 'heart')
    card.set_suit('club')
    assert 'club' == card.get_suit()
Ejemplo n.º 32
0
def test_invalid_rank_rejected():
    with pytest.raises(ValueError):
        Card(1, 'club')
        Card(16, 'club')
Ejemplo n.º 33
0
def test_invalid_suit_rejected():
    with pytest.raises(ValueError):
        Card(2, 'nonheart')
        Card(2, 'hearts')
        Card(2, 'hear')
Ejemplo n.º 34
0
def test_invalid_rank_set_rejected():
    card = Card(2, 'heart')
    with pytest.raises(ValueError):
        card.set_rank(16)
Ejemplo n.º 35
0
def test_cards_creation():
    for suit in ['heart', 'diamond', 'spade', 'club']:
        for rank in range(2, 15):
            card = Card(rank, suit)
            assert rank == card.get_rank()
            assert suit == card.get_suit()
Ejemplo n.º 36
0
def test_invalid_suit_set_rejected():
    card = Card(2, 'heart')
    with pytest.raises(ValueError):
        card.set_suit('he')