Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

unit tests for otherPickerView and majorMinorPickerView and tests for…

… the generated cifra through notification schemes
  • Loading branch information...
commit 7d4d1f406a53c8c1fd6835a79538e1207d646e66 1 parent 0f3302b
@setuid setuid authored
View
2  Decomposer/Decomposer/DCCifraPickerViewController.h
@@ -8,6 +8,8 @@
#import <UIKit/UIKit.h>
+UIKIT_EXTERN NSString* const CifraGenerationNotificationKey;
+
@interface DCCifraPickerViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>
+( DCCifraPickerViewController* ) cifraPickerViewController;
View
111 Decomposer/Decomposer/DCCifraPickerViewController.m
@@ -8,6 +8,8 @@
#import "DCCifraPickerViewController.h"
+NSString* const CifraGenerationNotificationKey = @"CifraGenerationNotification";
+
@interface DCCifraPickerViewController () {
IBOutlet UIPickerView* rootNotePickerView;
IBOutlet UIPickerView* majorMinorPickerView;
@@ -52,6 +54,12 @@ - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSIn
if( pickerView == rootNotePickerView )
return 12;
+ if( pickerView == majorMinorPickerView )
+ return 6;
+
+ if( pickerView == otherPickerView )
+ return 11;
+
return 0;
}
@@ -99,6 +107,69 @@ - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row f
default:
break;
}
+
+ if( pickerView == majorMinorPickerView )
+ switch (row) {
+ case 0:
+ title = @"m";
+ break;
+ case 1:
+ title = @"maj";
+ break;
+ case 2:
+ title = @"M";
+ break;
+ case 3:
+ title = @"aug";
+ break;
+ case 4:
+ title = @"dim";
+ break;
+ case 5:
+ title = @"sus";
+ break;
+ default:
+ break;
+ }
+
+ if( pickerView == otherPickerView )
+ switch (row) {
+ case 0:
+ title = @"2";
+ break;
+ case 1:
+ title = @"3";
+ break;
+ case 2:
+ title = @"4";
+ break;
+ case 3:
+ title = @"5";
+ break;
+ case 4:
+ title = @"6";
+ break;
+ case 5:
+ title = @"7";
+ break;
+ case 6:
+ title = @"b5";
+ break;
+ case 7:
+ title = @"9";
+ break;
+ case 8:
+ title = @"b9";
+ break;
+ case 9:
+ title = @"13";
+ break;
+ case 10:
+ title = @"b13";
+ break;
+ default:
+ break;
+ }
return title;
}
@@ -108,4 +179,44 @@ - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComp
}
+#pragma mark - Actions
+-( IBAction ) done:(id)sender
+{
+ [self dismissViewControllerAnimated: YES completion:
+ ^{
+ [self notifyCifraGeneration];
+ }];
+}
+
+-( void ) notifyCifraGeneration
+{
+ NSUInteger selectedRow;
+
+ selectedRow = [rootNotePickerView selectedRowInComponent:0];
+ NSString* rootTitle;
+ if( selectedRow != -1 )
+ rootTitle = [self pickerView: rootNotePickerView titleForRow: selectedRow forComponent: 0];
+ else
+ rootTitle = @"";
+
+ selectedRow = [majorMinorPickerView selectedRowInComponent:0];
+ NSString* majorMinorTitle;
+ if( selectedRow != -1 )
+ majorMinorTitle = [self pickerView: majorMinorPickerView titleForRow: selectedRow forComponent: 0];
+ else
+ majorMinorTitle = @"";
+
+ selectedRow = [otherPickerView selectedRowInComponent:0];
+ NSString* otherTitle;
+ if( selectedRow != -1 )
+ otherTitle = [self pickerView: otherPickerView titleForRow: selectedRow forComponent: 0];
+ else
+ otherTitle = @"";
+
+ NSString* cifra = [NSString stringWithFormat:@"%@%@%@", rootTitle, majorMinorTitle, otherTitle];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName: CifraGenerationNotificationKey
+ object: cifra];
+}
+
@end
View
144 Decomposer/Decomposer/DCCifraPickerViewController.xib
@@ -13,6 +13,7 @@
<array key="IBDocument.IntegratedClassDependencies">
<string>IBNSLayoutConstraint</string>
<string>IBProxyObject</string>
+ <string>IBUIButton</string>
<string>IBUIPickerView</string>
<string>IBUIView</string>
</array>
@@ -64,11 +65,47 @@
<string key="NSFrame">{{276, 0}, {90, 216}}</string>
<reference key="NSSuperview" ref="766721923"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView"/>
+ <reference key="NSNextKeyView" ref="770375889"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
<bool key="IBUIShowsSelectionIndicator">YES</bool>
</object>
+ <object class="IBUIButton" id="770375889">
+ <reference key="NSNextResponder" ref="766721923"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{453, 98}, {73, 44}}</string>
+ <reference key="NSSuperview" ref="766721923"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <string key="targetRuntimeIdentifier">IBIPadFramework</string>
+ <int key="IBUIContentHorizontalAlignment">0</int>
+ <int key="IBUIContentVerticalAlignment">0</int>
+ <int key="IBUIButtonType">1</int>
+ <string key="IBUINormalTitle">Done</string>
+ <object class="NSColor" key="IBUIHighlightedTitleColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MQA</bytes>
+ </object>
+ <object class="NSColor" key="IBUINormalTitleColor">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes>
+ </object>
+ <object class="NSColor" key="IBUINormalTitleShadowColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MC41AA</bytes>
+ </object>
+ <object class="IBUIFontDescription" key="IBUIFontDescription">
+ <int key="type">2</int>
+ <double key="pointSize">15</double>
+ </object>
+ <object class="NSFont" key="IBUIFont">
+ <string key="NSName">Helvetica-Bold</string>
+ <double key="NSSize">15</double>
+ <int key="NSfFlags">16</int>
+ </object>
+ </object>
</array>
<string key="NSFrameSize">{768, 221}</string>
<reference key="NSSuperview"/>
@@ -171,6 +208,15 @@
</object>
<int key="connectionID">44</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchEventConnection" key="connection">
+ <string key="label">done:</string>
+ <reference key="source" ref="770375889"/>
+ <reference key="destination" ref="606714003"/>
+ <int key="IBEventType">7</int>
+ </object>
+ <int key="connectionID">49</int>
+ </object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -196,6 +242,38 @@
<reference key="object" ref="766721923"/>
<array class="NSMutableArray" key="children">
<reference ref="944720021"/>
+ <object class="IBNSLayoutConstraint" id="1015762508">
+ <reference key="firstItem" ref="770375889"/>
+ <int key="firstAttribute">3</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="766721923"/>
+ <int key="secondAttribute">3</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">98</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="766721923"/>
+ <int key="scoringType">3</int>
+ <float key="scoringTypeFloat">9</float>
+ <int key="contentType">3</int>
+ </object>
+ <object class="IBNSLayoutConstraint" id="907314102">
+ <reference key="firstItem" ref="766721923"/>
+ <int key="firstAttribute">6</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="770375889"/>
+ <int key="secondAttribute">6</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">242</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="766721923"/>
+ <int key="scoringType">3</int>
+ <float key="scoringTypeFloat">9</float>
+ <int key="contentType">3</int>
+ </object>
<object class="IBNSLayoutConstraint" id="41698891">
<reference key="firstItem" ref="949835386"/>
<int key="firstAttribute">3</int>
@@ -294,6 +372,7 @@
</object>
<reference ref="1014774137"/>
<reference ref="949835386"/>
+ <reference ref="770375889"/>
</array>
<reference key="parent" ref="0"/>
</object>
@@ -414,6 +493,44 @@
<reference key="object" ref="41698891"/>
<reference key="parent" ref="766721923"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">45</int>
+ <reference key="object" ref="770375889"/>
+ <array class="NSMutableArray" key="children">
+ <object class="IBNSLayoutConstraint" id="804619416">
+ <reference key="firstItem" ref="770375889"/>
+ <int key="firstAttribute">7</int>
+ <int key="relation">0</int>
+ <nil key="secondItem"/>
+ <int key="secondAttribute">0</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">73</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="770375889"/>
+ <int key="scoringType">3</int>
+ <float key="scoringTypeFloat">9</float>
+ <int key="contentType">1</int>
+ </object>
+ </array>
+ <reference key="parent" ref="766721923"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">46</int>
+ <reference key="object" ref="907314102"/>
+ <reference key="parent" ref="766721923"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">47</int>
+ <reference key="object" ref="1015762508"/>
+ <reference key="parent" ref="766721923"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">48</int>
+ <reference key="object" ref="804619416"/>
+ <reference key="parent" ref="770375889"/>
+ </object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
@@ -422,13 +539,15 @@
<string key="-2.CustomClassName">UIResponder</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <array class="NSMutableArray" key="2.IBViewMetadataConstraints">
+ <array key="2.IBViewMetadataConstraints">
<reference ref="313070333"/>
<reference ref="955784470"/>
<reference ref="991301641"/>
<reference ref="248262448"/>
<reference ref="292975232"/>
<reference ref="41698891"/>
+ <reference ref="907314102"/>
+ <reference ref="1015762508"/>
</array>
<string key="21.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="22.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@@ -448,6 +567,14 @@
<reference ref="405273961"/>
</array>
<boolean value="NO" key="4.IBViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
+ <string key="45.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <array key="45.IBViewMetadataConstraints">
+ <reference ref="804619416"/>
+ </array>
+ <boolean value="NO" key="45.IBViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
+ <string key="46.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="47.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="48.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="7.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="8.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<array class="NSMutableArray" key="8.IBViewMetadataConstraints">
@@ -459,13 +586,24 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">44</int>
+ <int key="maxID">49</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">DCCifraPickerViewController</string>
<string key="superclassName">UIViewController</string>
+ <object class="NSMutableDictionary" key="actions">
+ <string key="NS.key.0">done:</string>
+ <string key="NS.object.0">id</string>
+ </object>
+ <object class="NSMutableDictionary" key="actionInfosByName">
+ <string key="NS.key.0">done:</string>
+ <object class="IBActionInfo" key="NS.object.0">
+ <string key="name">done:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ </object>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="majorMinorPickerView">UIPickerView</string>
<string key="otherPickerView">UIPickerView</string>
View
112 Decomposer/DecomposerTests/DCCifraPickerViewControllerTests.m
@@ -8,8 +8,36 @@
#import "DCCifraPickerViewControllerTests.h"
+@interface DCCifraPickerViewControllerTests ()
+{
+ BOOL didReceiveCifraGenerationNotification;
+ NSString* cifraGenerated;
+}
+
+@end
+
@implementation DCCifraPickerViewControllerTests
+-( void ) setUp
+{
+ [super setUp];
+ didReceiveCifraGenerationNotification = NO;
+ cifraGenerated = nil;
+
+ [[NSNotificationCenter defaultCenter] addObserver: self
+ selector: @selector( receivedCifraGenerationNotification: )
+ name: CifraGenerationNotificationKey
+ object: nil];
+}
+
+-( void ) tearDown
+{
+ [super tearDown];
+ [[NSNotificationCenter defaultCenter] removeObserver: self];
+ didReceiveCifraGenerationNotification = NO;
+ cifraGenerated = nil;
+}
+
-( void ) test_should_adhere_to_uipickerviewdelegate_and_datasource
{
DCCifraPickerViewController* dcp = [DCCifraPickerViewController cifraPickerViewController];
@@ -58,6 +86,90 @@ -( void ) test_root_picker_view_should_return_all_notes_chromatic_for_rows
STAssertTrue( [[dcp pickerView: rootPickerView titleForRow:11 forComponent: 0] isEqualToString:@"G# - Ab"], @"");
}
+-( void ) test_majorMinor_picker_view_should_have_6_rows
+{
+ DCCifraPickerViewController* dcp = [DCCifraPickerViewController cifraPickerViewController];
+ [self pingView: dcp.view];
+
+ UIPickerView* majorMinorPickerView = [dcp valueForKey:@"majorMinorPickerView"];
+ STAssertNotNil( majorMinorPickerView, @"" );
+
+ STAssertTrue( [dcp pickerView: majorMinorPickerView numberOfRowsInComponent:0] == 6, @"" );
+}
+
+-( void ) test_majorMinor_picker_view_should_return_all_possible_music_symbols
+{
+ DCCifraPickerViewController* dcp = [DCCifraPickerViewController cifraPickerViewController];
+ [self pingView: dcp.view];
+
+ UIPickerView* majorMinorPickerView = [dcp valueForKey:@"majorMinorPickerView"];
+ STAssertNotNil( majorMinorPickerView, @"" );
+
+ STAssertTrue( [[dcp pickerView: majorMinorPickerView titleForRow:0 forComponent: 0] isEqualToString:@"m"], @"");
+ STAssertTrue( [[dcp pickerView: majorMinorPickerView titleForRow:1 forComponent: 0] isEqualToString:@"maj"], @"");
+ STAssertTrue( [[dcp pickerView: majorMinorPickerView titleForRow:2 forComponent: 0] isEqualToString:@"M"], @"");
+ STAssertTrue( [[dcp pickerView: majorMinorPickerView titleForRow:3 forComponent: 0] isEqualToString:@"aug"], @"");
+ STAssertTrue( [[dcp pickerView: majorMinorPickerView titleForRow:4 forComponent: 0] isEqualToString:@"dim"], @"");
+ STAssertTrue( [[dcp pickerView: majorMinorPickerView titleForRow:5 forComponent: 0] isEqualToString:@"sus"], @"");
+}
+
+-( void ) test_otherNotes_picker_view_should_have_11_rows
+{
+ DCCifraPickerViewController* dcp = [DCCifraPickerViewController cifraPickerViewController];
+ [self pingView: dcp.view];
+
+ UIPickerView* otherNotesPickerView = [dcp valueForKey:@"otherPickerView"];
+ STAssertNotNil( otherNotesPickerView, @"" );
+
+ STAssertTrue( [dcp pickerView: otherNotesPickerView numberOfRowsInComponent:0] == 11, @"" );
+}
+
+-( void ) test_otherNotes_picker_view_should_return_all_possible_music_symbols
+{
+ DCCifraPickerViewController* dcp = [DCCifraPickerViewController cifraPickerViewController];
+ [self pingView: dcp.view];
+
+ UIPickerView* otherNotesPickerView = [dcp valueForKey:@"otherPickerView"];
+ STAssertNotNil( otherNotesPickerView, @"" );
+
+ STAssertTrue( [[dcp pickerView: otherNotesPickerView titleForRow:0 forComponent: 0] isEqualToString:@"2"], @"");
+ STAssertTrue( [[dcp pickerView: otherNotesPickerView titleForRow:1 forComponent: 0] isEqualToString:@"3"], @"");
+ STAssertTrue( [[dcp pickerView: otherNotesPickerView titleForRow:2 forComponent: 0] isEqualToString:@"4"], @"");
+ STAssertTrue( [[dcp pickerView: otherNotesPickerView titleForRow:3 forComponent: 0] isEqualToString:@"5"], @"");
+ STAssertTrue( [[dcp pickerView: otherNotesPickerView titleForRow:4 forComponent: 0] isEqualToString:@"6"], @"");
+ STAssertTrue( [[dcp pickerView: otherNotesPickerView titleForRow:5 forComponent: 0] isEqualToString:@"7"], @"");
+ STAssertTrue( [[dcp pickerView: otherNotesPickerView titleForRow:6 forComponent: 0] isEqualToString:@"b5"], @"");
+ STAssertTrue( [[dcp pickerView: otherNotesPickerView titleForRow:7 forComponent: 0] isEqualToString:@"9"], @"");
+ STAssertTrue( [[dcp pickerView: otherNotesPickerView titleForRow:8 forComponent: 0] isEqualToString:@"b9"], @"");
+ STAssertTrue( [[dcp pickerView: otherNotesPickerView titleForRow:9 forComponent: 0] isEqualToString:@"13"], @"");
+ STAssertTrue( [[dcp pickerView: otherNotesPickerView titleForRow:10 forComponent: 0] isEqualToString:@"b13"], @"");
+}
+
+-( void ) test_choosen_cifra_gets_notified_properly
+{
+ DCCifraPickerViewController* dcp = [DCCifraPickerViewController cifraPickerViewController];
+ [self pingView: dcp.view];
+
+ UIPickerView* rootNotePickerView = [dcp valueForKey:@"rootNotePickerView"];
+ UIPickerView* majorMinorPickerView = [dcp valueForKey:@"majorMinorPickerView"];
+ UIPickerView* otherNotesPickerView = [dcp valueForKey:@"otherPickerView"];
+
+ [rootNotePickerView selectRow: 0 inComponent:0 animated: YES];
+ [majorMinorPickerView selectRow: 0 inComponent:0 animated: YES];
+ [otherNotesPickerView selectRow: 5 inComponent:0 animated: YES];
+
+ [dcp performSelector:@selector(notifyCifraGeneration)];
+
+ STAssertTrue( didReceiveCifraGenerationNotification, @"" );
+ STAssertTrue( [cifraGenerated isEqualToString:@"Am7"], @"" );
+}
+
+-( void ) receivedCifraGenerationNotification:(NSNotification* ) notification
+{
+ didReceiveCifraGenerationNotification = YES;
+ cifraGenerated = (NSString*)notification.object;
+}
+
#pragma mark - Auxilary methods
-( void ) pingView:(UIView* ) view
{
Please sign in to comment.
Something went wrong with that request. Please try again.