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

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

@end

@implementation GanttTaskTests

- (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:1
              startDate:[NSDate dateWithString:@"2010-03-10 13:43:55 +0000"]
                endDate:[NSDate dateWithString:@"2010-03-12 13:43:55 +0000"]
                                    completion:0.85];
        task3 = [[GanttTask alloc] initWithTag:1
              startDate:[NSDate dateWithString:@"2010-03-10 13:43:55 +0000"]
                endDate:[NSDate dateWithString:@"2010-03-14 13:43:55 +0000"]
                                    completion:0.85];
        task4 = [[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.45];
    }
    return self;
}

- (void)testEquality
{

    UKTrue([task1 isEqualToTask:task2]);
    UKFalse([task1 isEqualToTask:task3]);
    UKFalse([task1 isEqualToTask:task4]);
}

- (void)testCoding
{
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:task1];
    GanttTask *aTask = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    UKTrue([task1 isEqualToTask:aTask]);
}

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

@end
