} END_TEST

/******** Create a number from the string "VI" -> toInt should return 6 *******/
START_TEST(roman_number_VI_should_have_value_6) {
   RomanNumber rn = newRomanNumber("VI");
   uint32_t value = to_a(rn);

   ck_assert_int_eq(value, 6);
} END_TEST
} END_TEST

/**** Create a number from the string "MCMXCIX" -> toInt should return 1999 ***/
START_TEST(roman_number_MCMXCIX_should_have_value_1999) {
   RomanNumber rn = newRomanNumber("MCMXCIX");
   uint32_t value = to_a(rn);

   ck_assert_int_eq(value, 1999);
} END_TEST
コード例 #3
0
ファイル: RomanNumberMath.c プロジェクト: kfries/Roman-Math-2
} END_TEST

/********************** Test Subtract Function, complex results *********************/
START_TEST(subtraction_complex_result) {
   RomanNumber rn1 = newRomanNumber("CL");
   RomanNumber rn2 = newRomanNumber("LX");

   RomanNumber difference = rnSubtract(rn1, rn2);

   ck_assert_str_eq("XC",  to_string(difference));
   ck_assert_int_eq(90, to_a(difference));
} END_TEST
コード例 #4
0
ファイル: RomanNumberMath.c プロジェクト: kfries/Roman-Math-2
} END_TEST

/******************** Test Subtract Function, start simple 10-5=5 *******************/
START_TEST(subtraction_10_minus_5_equals_5) {
   RomanNumber rn1 = newRomanNumber("X");
   RomanNumber rn2 = newRomanNumber("V");

   RomanNumber difference = rnSubtract(rn1, rn2);

   ck_assert_str_eq("V",  to_string(difference));
   ck_assert_int_eq(5, to_a(difference));
} END_TEST
コード例 #5
0
ファイル: RomanNumberMath.c プロジェクト: kfries/Roman-Math-2
} END_TEST

/******************** Test Subtract Function, start simple 10-1=9 *******************/
START_TEST(subtraction_10_minus_1_equals_9_subtractive_result) {
   RomanNumber rn1 = newRomanNumber("X");
   RomanNumber rn2 = newRomanNumber("I");

   RomanNumber difference = rnSubtract(rn1, rn2);

   ck_assert_str_eq("IX",  to_string(difference));
   ck_assert_int_eq(9, to_a(difference));
} END_TEST
コード例 #6
0
ファイル: RomanNumberMath.c プロジェクト: kfries/Roman-Math-2
} END_TEST

/***** Test Add Function with triple digit numbers, exercising full suite *****/
START_TEST(test_add_function_with_complex_numbers_143_plus_352_equals_495) {
   RomanNumber rn1 = newRomanNumber("CXLIII");
   RomanNumber rn2 = newRomanNumber("CCCLII");

   RomanNumber sum = rnAdd(rn1, rn2);

   ck_assert_str_eq("CDXCV",  to_string(sum));
   ck_assert_int_eq(495, to_a(sum));
} END_TEST
コード例 #7
0
ファイル: RomanNumberMath.c プロジェクト: kfries/Roman-Math-2
} END_TEST

/*** Test Add Function, using two digit numbers that require simplification ***/
START_TEST(test_add_function_with_moderately_complex_numbers_15_plus_17_equals_32) {
   RomanNumber rn1 = newRomanNumber("XV");
   RomanNumber rn2 = newRomanNumber("XVII");

   RomanNumber sum = rnAdd(rn1, rn2);

   ck_assert_str_eq("XXXII",  to_string(sum));
   ck_assert_int_eq(32, to_a(sum));
} END_TEST
コード例 #8
0
ファイル: RomanNumberMath.c プロジェクト: kfries/Roman-Math-2
} END_TEST

/**************** Test Add Function, using larger digits, 5+2=7 ***************/
START_TEST(test_add_function_with_simple_math_5_plus_2_equals_7) {
   RomanNumber rn1 = newRomanNumber("V");
   RomanNumber rn2 = newRomanNumber("II");

   RomanNumber sum = rnAdd(rn1, rn2);

   ck_assert_str_eq("VII",  to_string(sum));
   ck_assert_int_eq(7, to_a(sum));
} END_TEST
} END_TEST

/*******************************************************************************
 * Create a "toInt" function to return value of a Roman Number                 *
 ******************************************************************************/

/********* Create a "toInt" function to return value of a Roman Number ********/
START_TEST(roman_numberal_to_a_function) {
   RomanNumber rn = newRomanNumber("iiiiiii");
   uint32_t value = to_a(rn);

   ck_assert_int_eq(value, 7);
} END_TEST
コード例 #10
0
ファイル: RomanNumberMath.c プロジェクト: kfries/Roman-Math-2
} END_TEST

/*******************************************************************************
 * Use above API to add two roman numbers                                      *
 ******************************************************************************/

/******************** Test Add Function, start simple 1+1=2 *******************/
START_TEST(create_function_to_add_two_numbers) {
   RomanNumber rn1 = newRomanNumber("I");
   RomanNumber rn2 = newRomanNumber("I");

   RomanNumber sum = rnAdd(rn1, rn2);

   ck_assert_str_eq("II",  to_string(sum));
   ck_assert_int_eq(2, to_a(sum));
} END_TEST
コード例 #11
0
ファイル: RomanNumberMath.c プロジェクト: kfries/Roman-Math-2
} END_TEST


/*******************************************************************************
 * Use above API to subtract two roman numbers                                 *
 ******************************************************************************/

/******************** Test Subtract Function, start simple 2-1=1 *******************/
START_TEST(create_function_to_subtract_two_numbers) {
   RomanNumber rn1 = newRomanNumber("II");
   RomanNumber rn2 = newRomanNumber("I");

   RomanNumber difference = rnSubtract(rn1, rn2);

   ck_assert_str_eq("I",  to_string(difference));
   ck_assert_int_eq(1, to_a(difference));
} END_TEST
コード例 #12
0
ファイル: grid_map.cpp プロジェクト: MattUV/godot
void GridMap::_update_area_instances() {

	Transform base_xform;
	if (_in_tree)
		base_xform = get_global_transform();

	for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
		//this should somehow be faster...
		Area &a = *E->get();
		if (a.instance.is_valid() != _in_tree) {

			if (!_in_tree) {

				for (int i = 0; i < a.portals.size(); i++) {

					Area::Portal &p = a.portals[i];
					ERR_CONTINUE(!p.instance.is_valid());
					VisualServer::get_singleton()->free(p.instance);
					p.instance = RID();
				}

				VisualServer::get_singleton()->free(a.instance);
				a.instance = RID();

			} else {

				//a.instance = VisualServer::get_singleton()->instance_create2(base_room,get_world()->get_scenario());
				for (int i = 0; i < a.portals.size(); i++) {

					Area::Portal &p = a.portals[i];
					ERR_CONTINUE(p.instance.is_valid());
					p.instance = VisualServer::get_singleton()->instance_create2(a.base_portal, get_world()->get_scenario());
					VisualServer::get_singleton()->instance_set_room(p.instance, a.instance);
				}
			}
		}

		if (a.instance.is_valid()) {
			Transform xform;

			Vector3 from_a(a.from.x, a.from.y, a.from.z);
			Vector3 to_a(a.to.x, a.to.y, a.to.z);

			for (int i = 0; i < 3; i++) {
				xform.origin[i] = from_a[i] * cell_size;
				Vector3 s;
				s[i] = (to_a[i] - from_a[i]) * cell_size;
				xform.basis.set_axis(i, s);
			}

			VisualServer::get_singleton()->instance_set_transform(a.instance, base_xform * xform);

			for (int i = 0; i < a.portals.size(); i++) {

				Area::Portal &p = a.portals[i];
				ERR_CONTINUE(!p.instance.is_valid());

				VisualServer::get_singleton()->instance_set_transform(p.instance, base_xform * xform);
			}
		}
	}
}
コード例 #13
0
ファイル: grid_map.cpp プロジェクト: MattUV/godot
void GridMap::_update_areas() {

	//clear the portals
	for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
		//this should somehow be faster...
		Area &a = *E->get();
		a.portals.clear();
		if (a.instance.is_valid()) {
			VisualServer::get_singleton()->free(a.instance);
			a.instance = RID();
		}
	}

	//test all areas against all areas and create portals - this sucks (slow :( )
	for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) {
		Area &a = *E->get();
		if (a.exterior_portal) //that's pretty much all it does... yes it is
			continue;
		Vector3 from_a(a.from.x, a.from.y, a.from.z);
		Vector3 to_a(a.to.x, a.to.y, a.to.z);

		for (Map<int, Area *>::Element *F = area_map.front(); F; F = F->next()) {

			Area &b = *F->get();
			Vector3 from_b(b.from.x, b.from.y, b.from.z);
			Vector3 to_b(b.to.x, b.to.y, b.to.z);

			// initially test intersection and discards
			int axis = -1;
			float sign = 0;
			bool valid = true;
			Vector3 axmin, axmax;

			for (int i = 0; i < 3; i++) {

				if (from_a[i] == to_b[i]) {

					if (axis != -1) {
						valid = false;
						break;
					}

					axis = i;
					sign = -1;
				} else if (from_b[i] == to_a[i]) {

					if (axis != -1) {
						valid = false;
						break;
					}
					axis = i;
					sign = +1;
				}

				if (from_a[i] > to_b[i] || to_a[i] < from_b[i]) {
					valid = false;
					break;
				} else {

					axmin[i] = (from_a[i] > from_b[i]) ? from_a[i] : from_b[i];
					axmax[i] = (to_a[i] < to_b[i]) ? to_a[i] : to_b[i];
				}
			}

			if (axis == -1 || !valid)
				continue;

			Transform xf;

			for (int i = 0; i < 3; i++) {

				int ax = (axis + i) % 3;
				Vector3 axis_vec;
				float scale = (i == 0) ? sign : ((axmax[ax] - axmin[ax]) * cell_size);
				axis_vec[ax] = scale;
				xf.basis.set_axis((2 + i) % 3, axis_vec);
				xf.origin[i] = axmin[i] * cell_size;
			}

			Area::Portal portal;
			portal.xform = xf;
			a.portals.push_back(portal);
		}
	}

	_update_area_instances();
}