@@ -162,7 +162,7 @@ place for some of the data transforms and computations that now live in _lib/par
162
162
* margin of victory, if appropriate
163
163
164
164
Before we dive into migrating data transforms and computed values, let's start with the basics.
165
- We'll store our new election classes in a * lib/models.py* ([ Django[ ] users, this should be familiar).
165
+ We'll store our new election classes in a * lib/models.py* ([ Django] [ ] users, this should be familiar).
166
166
We'll store tests in a new * test_models.py* module.
167
167
168
168
[ Django ] : https://docs.djangoproject.com/en/dev/topics/db/models
@@ -182,7 +182,7 @@ Now let's start writing some test-driven code!
182
182
#### Add name bits
183
183
184
184
We'll start by creating a Candidate class that automatically parses a full name into first and last names (remember,
185
- candidate names in our source data are in the form * Lastname, Firstname* ).
185
+ candidate names in our source data are in the form * ( Lastname, Firstname* ).
186
186
187
187
* Create * elex4/tests/test_models.py* and add test for Candidate name parts ([ elex4.1.0] [ ] )
188
188
* Run test; see it fail
@@ -200,7 +200,7 @@ Let's apply a similar process for the party transformation.
200
200
201
201
#### Add party
202
202
203
- The candidate party requires special handling for Democratics and Republicans. Otherwise we'll default to the raw party value.
203
+ The candidate party requires special handling for Democrats and Republicans. Otherwise we'll default to the raw party value.
204
204
205
205
* Migrate party-related tests from * tests/test_parser.py* to * TestCandidate* in * tests/test_models.py* .
206
206
@@ -252,22 +252,22 @@ converting from a function-based to a class-based strategy hasn't corrupted the
252
252
253
253
### Add vote
254
254
255
- Each candidate has a single name and party, and numerous county-level results.
255
+ In addition to a name and party, each * Candidate * has county-level results.
256
256
As part of our summary report, county-level results need to be rolled up into a racewide total for each candidate.
257
257
At a high level, it seems natural for each candidate to track his or her own vote totals.
258
258
259
- Below are a few other basic assumptions, or requirements, that will help us flesh out
260
- vote-handling on the Candidate class:
259
+ Below are a few basic assumptions, or requirements, that will help us flesh out
260
+ vote-handling on the * Candidate* class:
261
261
262
262
* A candidate should start with zero votes
263
263
* Adding a vote should increment the vote count
264
264
* County-level results should be accessible
265
265
266
266
With this basic list of requirements in hand, we're ready to start coding. For each requirement, we'll start by
267
- writing a (failing) test that captures this assumption; then we'll write code to make the test pass. The goal
268
- is to capture our assumptions in the form of tests, and then write code to meet those assumnptions .
267
+ writing a (failing) test that captures this assumption; then we'll write code to make the test pass (i.e. meet
268
+ our assumption) .
269
269
270
- 1 . Add test for zero vote count as initial Candidate state ([ elex4.3.0] [ ] )
270
+ 1 . Add test to ensure * Candidate * 's initial vote count is zero ([ elex4.3.0] [ ] )
271
271
272
272
> Note: We created a new * TestCandidateVotes* class with a * setUp* method that lets us
273
273
> re-use the same candidate instance across all test methods. This
@@ -277,12 +277,20 @@ is to capture our assumptions in the form of tests, and then write code to meet
277
277
> we will have to do in the * TestCandidate* class)
278
278
279
279
1 . Run test; see it fail
280
- 1 . Update Candidate to have initial vote count of zero ([ elex4.3.1] [ ] )
280
+ 1 . Update * Candidate* class to have initial vote count of zero ([ elex4.3.1] [ ] )
281
281
1 . Run test; see it pass
282
+
283
+ Now let's add a method to update the candidate's total vote totals for each county result.
284
+
282
285
1 . Add test for * Candidate.add_votes* method ([ elex4.3.2] [ ] )
283
286
1 . Run test; see it fail
284
287
1 . Create the * Candidate.add_votes* method ([ elex4.3.3] [ ] )
285
288
1 . Run test; see it pass
289
+
290
+ Finally, let's stash the county-level results for each candidate.
291
+ Although we're not using these lower-level numbers in our summary report, it's easy enough to
292
+ add in case we need it for some other use case down the road.
293
+
286
294
1 . Create test for county_results attribute ([ elex4.3.4] [ ] )
287
295
1 . Run test; see it fail
288
296
1 . Update * Candidate.add_votes* method to store county-level results ([ elex4.3.5] [ ] )
0 commit comments