Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Node.h
- #import <Foundation/Foundation.h>
- @interface Node : NSObject
- @property (nonatomic, weak, readwrite) Node *next;
- //should the node contain objects
- //or just be a progression of pointers, I think pointers
- @end
- //Node.m
- #import <Foundation/Foundation.h>
- @interface Node : NSObject
- @property (nonatomic, weak, readwrite) Node *next;
- //should the node contain objects
- //or just be a progression of pointers, I think pointers
- @end
- //NList.h
- #import <Foundation/Foundation.h>
- #import "Card.h"
- #import "Node.h"
- @interface NList : NSObject
- @property (nonatomic,readonly) NSInteger size;
- @property (weak, readonly, nonatomic) Node *head;
- - (void)add:(NSObject *)node;
- - (id) initWithSize:(NSInteger *)size;
- @end
- //
- // NList.m
- #import "NList.h"
- @interface NList()
- @property (weak, nonatomic, readwrite) Node *head;
- @property (nonatomic,readwrite) NSInteger size;
- @property (nonatomic) NSInteger *num_nodes;
- @end
- @implementation NList
- @synthesize size = _size;
- @synthesize head = _head;
- //only reason dis is here because it is required [I think.]
- - (id)init {
- self = [super init];
- if (self) {
- self.head = nil; //as opposed to _head, I think
- self.num_nodes = 0;
- }
- return self;
- }
- - (id) initWithSize:(NSInteger *)size {
- self = [super init];
- if (self){
- self.head = nil;
- self.size = size;
- self.num_nodes = 0;
- }
- return self;
- }
- - (void)add:(NSObject *)node {
- Node *newNode = [[Node alloc] init];
- if (self.head)
- newNode.next = self.head;
- else
- self.head = newNode;
- self.num_nodes++;
- }
- @end
- //test file
- // XCT for assertions
- - (void)testAdd
- {
- NList *testList = [[NList alloc] initWithSize:2];
- NSObject *testNodeOne = @1;
- [testList add:(testNodeOne)];
- XCTAssertNotNil(testList.head);
- NSObject *testNodeTwo = @3;
- [testList add:testNodeTwo];
- XCTAssertNotNil(testList.head);
- XCTAssertNotNil(testList.head.next); ((testList.head.next) != nil) failed: throwing "-[__NSCFNumber next]: unrecognized selector sent to instance 0x8d75720"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement