Skip to content

Commit

Permalink
Add figures counts in each tableview section header (#5).
Browse files Browse the repository at this point in the history
  • Loading branch information
seiza committed May 29, 2012
1 parent c2c5dc8 commit 8e26a0d
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Legomni.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
C483C3F615752CEF00E7F77C /* SkaterGirl.plist in Resources */ = {isa = PBXBuildFile; fileRef = C483C3E615752CEF00E7F77C /* SkaterGirl.plist */; };
C483C3F715752CEF00E7F77C /* Sleepyhead.plist in Resources */ = {isa = PBXBuildFile; fileRef = C483C3E715752CEF00E7F77C /* Sleepyhead.plist */; };
C483C3F815752CEF00E7F77C /* Surgeon.plist in Resources */ = {isa = PBXBuildFile; fileRef = C483C3E815752CEF00E7F77C /* Surgeon.plist */; };
C483C3FB1575367E00E7F77C /* SerieTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C483C3FA1575367E00E7F77C /* SerieTests.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -270,6 +271,8 @@
C483C3E615752CEF00E7F77C /* SkaterGirl.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = SkaterGirl.plist; sourceTree = "<group>"; };
C483C3E715752CEF00E7F77C /* Sleepyhead.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Sleepyhead.plist; sourceTree = "<group>"; };
C483C3E815752CEF00E7F77C /* Surgeon.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Surgeon.plist; sourceTree = "<group>"; };
C483C3F91575367E00E7F77C /* SerieTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SerieTests.h; sourceTree = "<group>"; };
C483C3FA1575367E00E7F77C /* SerieTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SerieTests.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -363,6 +366,8 @@
children = (
C40FCDEA156D560900249D22 /* LegomniTests.h */,
C40FCDEB156D560900249D22 /* LegomniTests.m */,
C483C3F91575367E00E7F77C /* SerieTests.h */,
C483C3FA1575367E00E7F77C /* SerieTests.m */,
C40FCDE5156D560900249D22 /* Supporting Files */,
);
path = LegomniTests;
Expand Down Expand Up @@ -795,6 +800,7 @@
buildActionMask = 2147483647;
files = (
C40FCDEC156D560900249D22 /* LegomniTests.m in Sources */,
C483C3FB1575367E00E7F77C /* SerieTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
5 changes: 4 additions & 1 deletion Legomni/MasterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [NSString stringWithFormat:@"%@ %d", (NSLocalizedString(@"Série", @"Série")), [self serieForIndex:section].index];
Serie* serie = [self serieForIndex:section];
int count = [serie differentFiguresCount];
int doublesCount = [serie doubleCount];
return [NSString stringWithFormat:@"%@ %d (%d/16 + %d)", (NSLocalizedString(@"Série", @"Série")), serie.index, count, doublesCount];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
Expand Down
3 changes: 3 additions & 0 deletions Legomni/Models/Serie.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@

- (id)initWithIndex:(int)index;

- (int) differentFiguresCount;
- (int) doubleCount;

@end
17 changes: 17 additions & 0 deletions Legomni/Models/Serie.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,21 @@ - (id)initWithIndex:(int)i {
return self;
}


- (int) differentFiguresCount {
int count = 0;
for (Figure* f in self.figures) {
if (f.quantity > 0) ++count;
}
return count;
}

- (int) doubleCount {
int count = 0;
for (Figure* f in self.figures) {
if (f.quantity > 1) count += f.quantity - 1;
}
return count;
}

@end
2 changes: 1 addition & 1 deletion LegomniTests/LegomniTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// LegomniTests
//
// Created by Jacques COUVREUR on 23.05.12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
// Copyright (c) 2012 me.couvreur.jacques. All rights reserved.
//

#import <SenTestingKit/SenTestingKit.h>
Expand Down
4 changes: 2 additions & 2 deletions LegomniTests/LegomniTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// LegomniTests
//
// Created by Jacques COUVREUR on 23.05.12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
// Copyright (c) 2012 me.couvreur.jacques. All rights reserved.
//

#import "LegomniTests.h"
Expand All @@ -26,7 +26,7 @@ - (void)tearDown

- (void)testExample
{
STFail(@"Unit tests are not implemented yet in LegomniTests");
// STFail(@"Unit tests are not implemented yet in LegomniTests");
}

@end
13 changes: 13 additions & 0 deletions LegomniTests/SerieTests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// SerieTests.h
// Legomni
//
// Created by Jacques COUVREUR on 29.05.12.
// Copyright (c) 2012 me.couvreur. All rights reserved.
//

#import <SenTestingKit/SenTestingKit.h>

@interface SerieTests : SenTestCase

@end
40 changes: 40 additions & 0 deletions LegomniTests/SerieTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// SerieTests.m
// Legomni
//
// Created by Jacques COUVREUR on 29.05.12.
// Copyright (c) 2012 me.couvreur. All rights reserved.
//

#import "SerieTests.h"
#import "Serie.h"
#import "Figure.h"

@implementation SerieTests

- (void) test_differentFiguresCount_and_doubleCount {
Serie* serie = [[Serie alloc] initWithIndex:3];
{
Figure* f = [[Figure alloc] initWithCode:@"0" andSerie:3];
[serie.figures addObject:f];
f.quantity = 0;
STAssertEquals([serie differentFiguresCount], 0, nil);
STAssertEquals([serie doubleCount], 0, nil);
}
{
Figure* f = [[Figure alloc] initWithCode:@"1" andSerie:3];
[serie.figures addObject:f];
f.quantity = 1;
STAssertEquals([serie differentFiguresCount], 1, nil);
STAssertEquals([serie doubleCount], 0, nil);
}
{
Figure* f = [[Figure alloc] initWithCode:@"2" andSerie:3];
[serie.figures addObject:f];
f.quantity = 2;
STAssertEquals([serie differentFiguresCount], 2, nil);
STAssertEquals([serie doubleCount], 1, nil);
}
}

@end

0 comments on commit 8e26a0d

Please sign in to comment.