Bingo for meetings–working at score-part 5
Bingo
Bingo is a small project, written in TypeScript , and developed with Alexandru Badita in launch break (one hour - more or less). You can find sources at https://github.com/alexandru360/PresentationBingoCards/ . Those are my blog posts for Bingo : ( scroll below for the post)The next requirement is saying ( https://github.com/alexandru360/PresentationBingoCards/projects/1#card-24165817 )
Checking cards:
A total score will be displayed when checking / unchecking
There are 2 things very clear:
- The name of the user story is not reflecting the content
- It should not be just the total score, but also should be the percentage of the bingo cards checked from the total number of cards. It is not so difficult to have the total number of cards, so let’s add this.
We have put this code:
public TotalNumberOfCardsChecked():number{ return this.Cards.filter(it=>it.IsChecked()).length ; }
And we put test
it('number of cards checked', () => { const mf=new MeetingsFactory(); const m1=mf.CreateMeeting("andrei","first meeting"); console.log(m1.Cards.length); expect(m1.TotalNumberOfCardsChecked()).toBe(0); m1.CheckCardByParticipant(m1.Cards[0], m1.Participants[0]); expect(m1.TotalNumberOfCardsChecked()).toBe(1); })
We see that for TotalNumberOfCardsChecked and AllUnchecked we have the same code
public AllUnchecked(): boolean{ return (this.Cards.filter(it=>it.IsChecked()).length === 0); } //other code public TotalNumberOfCardsChecked():number{ return this.Cards.filter(it=>it.IsChecked()).length ; }
and because we hate copy paste we refactor and re-test
So we refactor a bit .
public AllUnchecked(): boolean{ return (this.TotalNumberOfCardsChecked() === 0); }
And because we have tests, that means we are pretty confident of what are we doing
Also, we said that we have to calculate the total number of checked cards. This is not so difficult, and it alleviates the Law of Dots /Demeter (https://haacked.com/archive/2009/07/14/law-of-demeter-dot-counting.aspx)
public TotalNumberOfCards():number{ return this.Cards.length; }
The consequence ? To maintain code coverage, we should add another line of test:
expect(m1.TotalNumberOfCards()).toBe(Cards.DefaultCards().length);
Also, because the requirement says to display, and we are not yet to the GUI, I have put a new note that says
Design:
– [ ] display total number of cards checked or percentage ( use TotalNumberOfCardsChecked and/or TotalNumberOfCards)
Leave a Reply