Skip to content

Instantly share code, notes, and snippets.

@wookay
Created October 11, 2010 08:57
Show Gist options
  • Save wookay/620238 to your computer and use it in GitHub Desktop.
Save wookay/620238 to your computer and use it in GitHub Desktop.
장기 유닛 테스트
//
// TestJanggi.m
// JanggiNorm
//
// Created by Woo-Kyoung Noh on 13/09/10.
// Copyright 2010 factorcat. All rights reserved.
//
#import "TestJanggi.h"
#import "JanggiManager.h"
#import "JangUnit.h"
#import "UnitTest.h"
#import "JanggiPan.h"
#import "GeometryExt.h"
#import "Logger.h"
@implementation TestJanggi
-(void) test_janggi {
JangUnit* choGung = [JangUnit unitWithName:@"초궁"];
assert_equal(NATION_CHO, choGung.nation);
assert_equal(GIMUL_GUNG, choGung.gimul);
assert_equal(CGPointZero, choGung.position);
[JANGMAN.board putUnit:choGung];
assert_equal(JANGGI_PAN_RECT.size, JANGMAN.pan.gridSize);
assert_false([JANGMAN.board hasUnitAt:CGPointMake(5, 9)]);
[JANGMAN.board setPosition:choGung To:CGPointMake(5,9)];
assert_true([JANGMAN.board hasUnitAt:CGPointMake(5, 9)]);
assert_equal(8, [JANGMAN.board movablePositions:choGung].count);
[JANGMAN.board move:choGung To:CGPointMake(5,10)];
assert_equal(3, [JANGMAN.board movablePositions:choGung].count);
assert_equal(false, CGRectHasPoint(HAN_GUNG_RECT, choGung.position));
assert_equal(true, CGRectHasPoint(CHO_GUNG_RECT, choGung.position));
assert_equal(true, CGRectHasPoint(CHO_GUNG_RECT, CGPointMake(5, 9)));
assert_equal(CGPointMake(5,10), choGung.position);
assert_equal(0, [JANGMAN.board targetablePositions:choGung].count);
assert_equal(false, [JANGMAN.board enemyCouldJanggun:choGung]);
JangUnit* hanZol = [JangUnit unitWithName:@"한병"];
hanZol.position = CGPointMake(5, 9);
[JANGMAN.board putUnit:hanZol];
assert_equal(true, [JANGMAN.board enemyCouldJanggun:choGung]);
assert_equal(1, [JANGMAN.board targetablePositions:choGung].count);
assert_equal(0, [JANGMAN.board movablePositions:choGung].count);
assert_equal(4, [JANGMAN.board movablePositions:hanZol].count);
assert_equal(1, [JANGMAN.board targetablePositions:hanZol].count);
[JANGMAN.board popUnit:CGPointMake(5, 9)];
JangUnit* hanMa = [JangUnit unitWithName:@"한마"];
hanMa.position = CGPointMake(7, 9);
[JANGMAN.board putUnit:hanMa];
assert_equal(5, [JANGMAN.board movablePositions:hanMa].count);
assert_equal(1, [JANGMAN.board targetablePositions:hanMa].count);
JangUnit* choSang = [JangUnit unitWithName:@"초상"];
choSang.position = CGPointMake(5, 6);
[JANGMAN.board putUnit:choSang];
assert_equal(1, [JANGMAN.board targetablePositions:choSang].count);
assert_equal(0, [JANGMAN.board movablePositions:choSang].count);
JangUnit* hanCha = [JangUnit unitWithName:@"한차"];
hanCha.position = CGPointMake(5, 5);
[JANGMAN.board putUnit:hanCha];
assert_equal(12, [JANGMAN.board movablePositions:hanCha].count);
assert_equal(1, [JANGMAN.board targetablePositions:hanCha].count);
[JANGMAN.board move:hanCha To:CGPointMake(5,4)];
JangUnit* hanPo = [JangUnit unitWithName:@"한포"];
hanPo.position = CGPointMake(5, 2);
[JANGMAN.board putUnit:hanPo];
assert_equal(1, [JANGMAN.board movablePositions:hanPo].count);
assert_equal(1, [JANGMAN.board targetablePositions:hanPo].count);
JangUnit* choSa = [JangUnit unitWithName:@"초사"];
choSa.position = CGPointMake(5, 9);
[JANGMAN.board putUnit:choSa];
assert_equal(0, [JANGMAN.board targetablePositions:choSa].count);
assert_equal(1, [JANGMAN.board movablePositions:choSa].count);
assert_equal(0x01 , [JANGMAN matchPlayerGroup]);
[JANGMAN.board attack:hanCha To:choSang.position];
[JANGMAN.board moveBack];
[JANGMAN.board attack:hanCha To:choSang.position];
log_info(@"JANGMAN panInfo %@", [JANGMAN panInfo]);
}
@end
@wookay
Copy link
Author

wookay commented Oct 11, 2010

Started
..............................           TestJanggi.m #098   JANGMAN panInfo 
--- --- --- --- --- --- --- --- ---
--- --- --- ---  포 --- --- --- ---
--- --- --- --- --- --- --- --- ---
--- --- --- --- --- --- --- --- ---
--- --- --- --- --- --- --- --- ---
--- --- --- ---  차 --- --- --- ---
--- --- --- --- --- --- --- --- ---
--- --- --- --- --- --- --- --- ---
--- --- --- --- *사 ---  마 --- ---
--- --- --- --- *궁 --- --- --- ---

Finished in 0.0674 seconds.

3 tests, 30 assertions, 0 failures, 0 errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment