Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. //Node.h
  2.  
  3. #import <Foundation/Foundation.h>
  4.  
  5. @interface Node : NSObject
  6. @property (nonatomic, weak, readwrite) Node *next;
  7. //should the node contain objects
  8. //or just be a progression of pointers, I think pointers
  9. @end
  10.  
  11. //Node.m
  12.  
  13. #import <Foundation/Foundation.h>
  14.  
  15. @interface Node : NSObject
  16. @property (nonatomic, weak, readwrite) Node *next;
  17. //should the node contain objects
  18. //or just be a progression of pointers, I think pointers
  19. @end
  20.  
  21. //NList.h
  22. #import <Foundation/Foundation.h>
  23. #import "Card.h"
  24. #import "Node.h"
  25.  
  26. @interface NList : NSObject
  27. @property (nonatomic,readonly) NSInteger size;
  28. @property (weak, readonly, nonatomic) Node *head;
  29.  
  30. - (void)add:(NSObject *)node;
  31. - (id) initWithSize:(NSInteger *)size;
  32.  
  33. @end
  34.  
  35.  
  36. //
  37. // NList.m
  38. #import "NList.h"
  39. @interface NList()
  40. @property (weak, nonatomic, readwrite) Node *head;
  41. @property (nonatomic,readwrite) NSInteger size;
  42. @property (nonatomic) NSInteger *num_nodes;
  43. @end
  44.  
  45. @implementation NList
  46. @synthesize size = _size;
  47. @synthesize head = _head;
  48.  
  49. //only reason dis is here because it is required [I think.]
  50. - (id)init {
  51. self = [super init];
  52. if (self) {
  53. self.head = nil; //as opposed to _head, I think
  54. self.num_nodes = 0;
  55. }
  56. return self;
  57. }
  58.  
  59. - (id) initWithSize:(NSInteger *)size {
  60. self = [super init];
  61. if (self){
  62. self.head = nil;
  63. self.size = size;
  64. self.num_nodes = 0;
  65. }
  66. return self;
  67. }
  68.  
  69. - (void)add:(NSObject *)node {
  70. Node *newNode = [[Node alloc] init];
  71. if (self.head)
  72. newNode.next = self.head;
  73. else
  74. self.head = newNode;
  75.  
  76. self.num_nodes++;
  77. }
  78. @end
  79.  
  80.  
  81.  
  82.  
  83.  
  84. //test file
  85.  
  86. // XCT for assertions
  87. - (void)testAdd
  88. {
  89. NList *testList = [[NList alloc] initWithSize:2];
  90. NSObject *testNodeOne = @1;
  91. [testList add:(testNodeOne)];
  92. XCTAssertNotNil(testList.head);
  93. NSObject *testNodeTwo = @3;
  94.  
  95. [testList add:testNodeTwo];
  96. XCTAssertNotNil(testList.head);
  97. XCTAssertNotNil(testList.head.next); ((testList.head.next) != nil) failed: throwing "-[__NSCFNumber next]: unrecognized selector sent to instance 0x8d75720"
  98.  
  99.  
  100.  
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement