Repository: realm/realm-swift
File: src/tightdb/objc/test/dynamic_table.mm (Objective-C++)

Code before:
    STAssertTrue(table.columnCount  == 10, @"10 columns added");

    for (int i=0;i<10;i++) {
        [table removeColumnWithIndex:0];
    }

    STAssertEquals(table.columnCount, (NSUInteger)0, @"Colums removed");
    STAssertThrows([table removeColumnWithIndex:1], @"No columns added");
    STAssertThrows([table removeColumnWithIndex:-1], @"Less than zero colIndex");
}

-(void)testRenameColumns
{
    TDBTable *table = [[TDBTable alloc] init];
    STAssertThrows([table renameColumnWithIndex:0 to:@"someName"], @"Out of bounds");
    
    [table addColumnWithName:@"oldName" type:TDBIntType];
    
    [table renameColumnWithIndex:0 to:@"newName"];
    STAssertEqualObjects([table nameOfColumnWithIndex:0], @"newName", @"Get column name");
    
    [table renameColumnWithIndex:0 to:@"evenNewerName"];
    STAssertEqualObjects([table nameOfColumnWithIndex:0], @"evenNewerName", @"Get column name");
    
    STAssertThrows([table renameColumnWithIndex:1 to:@"someName"], @"Out of bounds");
    STAssertThrows([table renameColumnWithIndex:100 to:@"someName"], @"Out of bounds");
    STAssertThrows([table renameColumnWithIndex:-1 to:@"someName"], @"Less than zero colIndex");
}

/*
- (void)testColumnlessCount
{
    TDBTable* t = [[TDBTable alloc] init];
    STAssertEquals((size_t)0, [t count], @"Columnless table has 0 rows.");     
}

- (void)testColumnlessIsEmpty
{
    TDBTable* t = [[TDBTable alloc] init];
    STAssertTrue([t isEmpty], @"Columnless table is empty.");
}

- (void)testColumnlessClear
{
    TDBTable* t = [[TDBTable alloc] init];
    [t clear];
}

- (void)testColumnlessOptimize
{
    TDBTable* t = [[TDBTable alloc] init];

Review comment (suggestion):
The argument `renameColumnWithIndex` is unsigned so this is interpreted as a large positive number which you test in the line above.


Code after:
    STAssertTrue(table.columnCount  == 10, @"10 columns added");

    for (int i=0;i<10;i++) {
        [table removeColumnWithIndex:0];
    }

    STAssertEquals(table.columnCount, (NSUInteger)0, @"Colums removed");
    STAssertThrows([table removeColumnWithIndex:1], @"No columns added");
    STAssertThrows([table removeColumnWithIndex:-1], @"Less than zero colIndex");
}

-(void)testRenameColumns
{
    TDBTable *table = [[TDBTable alloc] init];
    STAssertThrows([table renameColumnWithIndex:0 to:@"someName"], @"Out of bounds");
    
    [table addColumnWithName:@"oldName" type:TDBIntType];
    
    [table renameColumnWithIndex:0 to:@"newName"];
    STAssertEqualObjects([table nameOfColumnWithIndex:0], @"newName", @"Get column name");
    
    [table renameColumnWithIndex:0 to:@"evenNewerName"];
    STAssertEqualObjects([table nameOfColumnWithIndex:0], @"evenNewerName", @"Get column name");
    
    STAssertThrows([table renameColumnWithIndex:1 to:@"someName"], @"Out of bounds");
    STAssertThrows([table renameColumnWithIndex:-1 to:@"someName"], @"Less than zero colIndex");
    
    [table addColumnWithName:@"oldName2" type:TDBIntType];
    [table renameColumnWithIndex:1 to:@"newName2"];
    STAssertEqualObjects([table nameOfColumnWithIndex:1], @"newName2", @"Get column name");
    
    STAssertThrows([table renameColumnWithIndex:2 to:@"someName"], @"Out of bounds");
}

/*
- (void)testColumnlessCount
{
    TDBTable* t = [[TDBTable alloc] init];
    STAssertEquals((size_t)0, [t count], @"Columnless table has 0 rows.");     
}

- (void)testColumnlessIsEmpty
{
    TDBTable* t = [[TDBTable alloc] init];
    STAssertTrue([t isEmpty], @"Columnless table is empty.");
}

- (void)testColumnlessClear
{
    TDBTable* t = [[TDBTable alloc] init];
    [t clear];