#import <UnitKit/UnitKit.h>
#import "GanttModel.h"

@interface GanttModelTests : NSObject <UKTest>
{
    GanttTask *task1;
    GanttTask *task2;
    GanttTask *task3;
    GanttTask *task4;
    GanttModel *tasks;
}

@end

@implementation GanttModelTests

- (id)init
{
    self = [super init];
    if (self)
    {
        task1 = [[GanttTask alloc] initWithTag:1
                 startDate:[NSDate dateWithString:@"2010-03-10 13:43:55 +0000"]
                   endDate:[NSDate dateWithString:@"2010-03-12 13:43:55 +0000"]
                completion:0.85];
        task2 = [[GanttTask alloc] initWithTag:2
                 startDate:[NSDate dateWithString:@"2010-03-11 13:43:55 +0000"]
                   endDate:[NSDate dateWithString:@"2010-03-12 13:43:55 +0000"]
                completion:0.80];
        task3 = [[GanttTask alloc] initWithTag:3
                 startDate:[NSDate dateWithString:@"2010-03-12 13:43:55 +0000"]
                   endDate:[NSDate dateWithString:@"2010-03-14 13:43:55 +0000"]
                completion:0.55];
        task4 = [[GanttTask alloc] initWithTag:4
                 startDate:[NSDate dateWithString:@"2010-03-09 13:43:55 +0000"]
                   endDate:[NSDate dateWithString:@"2010-03-12 13:43:55 +0000"]
                completion:0.45];
        tasks = [[GanttModel alloc] init];
        [tasks addTask: task1];
        [tasks addTask: task2];
        [tasks addTask: task3];
        [tasks addTask: task4];
    }
    return self;
}

- (void)testCoding
{
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:tasks];
    GanttModel *model = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    UKTrue([task1 isEqualToTask:[model taskAtIndex:0]]);
    UKTrue([task2 isEqualToTask:[model taskAtIndex:1]]);
    UKTrue([task3 isEqualToTask:[model taskAtIndex:2]]);
    UKTrue([task4 isEqualToTask:[model taskAtIndex:3]]);
}

- (void)dealloc
{
    DESTROY(task1);
    DESTROY(task2);
    DESTROY(task3);
    DESTROY(task4);
    DESTROY(tasks);
    [super dealloc];
}

@end
