示例#1
0
		public void selector_1()
        {
            _log.enterScope();

            UtilityVector vector = new UtilityVector(0, 1, 0, 2);
            BehaviorAction action = new BehaviorAction(delegate() { return BehaviorReturnCode.Success; });
            UtilityPair pair = new UtilityPair(vector, action);
			UtilitySelector sel = new UtilitySelector(delegate(){return new UtilityVector(0,1,1,2);},pair,pair);

			BehaviorReturnCode result = sel.Behave();

			Verify.VerifyNotEquals("basic vector compare", true, result, BehaviorReturnCode.Failure);

            _log.exitScope();
        }
示例#2
0
		public void selector_3(){
			_log.enterScope();

			//build vectors
			UtilityVector a = new UtilityVector(0, 1, 0, 1);
			UtilityVector b = new UtilityVector(1, 1, 0, 0);
			UtilityVector c = new UtilityVector(1, 0, 1, 0);
			UtilityVector d = new UtilityVector(0, 0, 1, 1);

			string choice = "";

			//build actions that change choice if called
			BehaviorAction aa = new BehaviorAction (delegate() {
				choice = "a";
				return BehaviorReturnCode.Success;
			});
			BehaviorAction ba = new BehaviorAction (delegate() {
				choice = "b";
				return BehaviorReturnCode.Success;
			});
			BehaviorAction ca = new BehaviorAction (delegate() {
				choice = "c";
				return BehaviorReturnCode.Success;
			});
			BehaviorAction da = new BehaviorAction (delegate() {
				choice = "d";
				return BehaviorReturnCode.Success;
			});

			//build the appropraite pairs
			UtilityPair ap = new UtilityPair (a, aa);
			UtilityPair bp = new UtilityPair (b, ba);
			UtilityPair cp = new UtilityPair (c, ca);
			UtilityPair dp = new UtilityPair (d, da);


			//execute tests
			UtilitySelector sel = new UtilitySelector (delegate() {
				return new UtilityVector (0.5f,0.7f,0.4f,0.8f);
			}, ap, bp, cp, dp);

			sel.Behave ();

			Verify.VerifyTrue ("a chosen", true, choice == "a");

			sel = new UtilitySelector (delegate() {
				return new UtilityVector (0.7f,0.8f,0.5f,0.4f);
			}, ap, bp, cp, dp);

			sel.Behave ();

			Verify.VerifyTrue ("b chosen", true, choice == "b");

			sel = new UtilitySelector (delegate() {
				return new UtilityVector (0.7f,0.5f,0.8f,0.4f);
			}, ap, bp, cp, dp);

			sel.Behave ();

			Verify.VerifyTrue ("c chosen", true, choice == "c");

			sel = new UtilitySelector (delegate() {
				return new UtilityVector (0.5f,0.4f,0.7f,0.8f);
			}, ap, bp, cp, dp);

			sel.Behave ();

			Verify.VerifyTrue ("d chosen", true, choice == "d");


			_log.exitScope ();
		}