//******************************************************
    //******************************************************
    //**	INTERFACE CLASS
    //******************************************************
    //******************************************************

    // PRIVATE
    ///<summary>
    ///	DEMO
    //
    ///</summary>
    private void _doDemoOfInterface()
    {
        // DECLARE WITH TYPE OF INTERFACE
        //	(TYPE 'IMixer' GIVES MORE ARCHITECTURAL FLEXIBLITY THAN TYPE 'HandMixer')
        IMixer iMixer = new HandMixer();

        // USE
        iMixer.doMixing();
        Debug.Log("iMixer: " + iMixer);
    }
    // PRIVATE
    ///<summary>
    ///	DEMO
    //
    ///</summary>
    private void _doDemoOfUpCasting()
    {
        // DECLARE WITH TYPE OF SUPERCLASS
        //	ADVANCED: YOU MAY SOME DAY HAVE REASONS TO DO THIS
        HandMixer handMixer = new HandMixer();

        //	NOTICE: 'UPCASTING' HAPPENS AUTOMATICALLY HERE. THE METHOD WANTS A 'Mixer'
        //			AND THE COMPILER KNOWS THAT 'HandMixer' CAN BE UPCAST PROPERLY
        //			'UPCASTING' IS TO MAKE THE TYPE BEHAVE AS A *LESS* SPECIFIC TYPE.
        //			LESS SPECIFIC MEANS 'LIKE A SUPERCLASS' IN THIS CASE
        _acceptOnlyAMixer(handMixer);

        //	YOU CAN MANUALLY UPCAST TOO, AND THERE MAY BE (RARE) REASONS TO DO THAT
        (handMixer as Mixer).doMixing();
    }
Esempio n. 3
0
        public void HandMixer_1_Round_Of_Shuffle()
        {
            var simpleMixer   = new HandMixer <string>(1);
            var originalArray = new List <string>()
            {
                "a", "b", "c", "d", "e"
            };
            var shuffledArray = simpleMixer.Shuffle(originalArray).ToList();

            Assert.AreEqual(originalArray.Count(), shuffledArray.Count());
            Assert.AreEqual(0, originalArray.Except(shuffledArray).Count());
            Assert.AreEqual(originalArray.Distinct().Count(), shuffledArray.Distinct().Count());
            Assert.AreEqual(5, originalArray.Intersect(shuffledArray).Count());

            Assert.IsTrue(shuffledArray[0] != "a");
            Assert.IsTrue(shuffledArray[1] != "b");
            Assert.IsTrue(shuffledArray[2] != "c");
            Assert.IsTrue(shuffledArray[3] != "d");
            Assert.IsTrue(shuffledArray[4] != "e");

            Assert.IsTrue(shuffledArray[0] == "e" || shuffledArray[0] == "d" || shuffledArray[0] == "c");
        }
	// PRIVATE
	///<summary>
	///	DEMO
	//
	///</summary>
	private void _doDemoOfUpCasting () 
	{
		// DECLARE WITH TYPE OF SUPERCLASS 
		//	ADVANCED: YOU MAY SOME DAY HAVE REASONS TO DO THIS
		HandMixer handMixer = new HandMixer ();
		
		//	NOTICE: 'UPCASTING' HAPPENS AUTOMATICALLY HERE. THE METHOD WANTS A 'Mixer'
		//			AND THE COMPILER KNOWS THAT 'HandMixer' CAN BE UPCAST PROPERLY
		//			'UPCASTING' IS TO MAKE THE TYPE BEHAVE AS A *LESS* SPECIFIC TYPE.
		//			LESS SPECIFIC MEANS 'LIKE A SUPERCLASS' IN THIS CASE
		_acceptOnlyAMixer (handMixer);
		
		//	YOU CAN MANUALLY UPCAST TOO, AND THERE MAY BE (RARE) REASONS TO DO THAT
		(handMixer as Mixer).doMixing();
		
	}
	//******************************************************
	//******************************************************
	//**	INTERFACE CLASS
	//******************************************************
	//******************************************************
	
	// PRIVATE
	///<summary>
	///	DEMO
	//
	///</summary>
	private void _doDemoOfInterface () 
	{
		// DECLARE WITH TYPE OF INTERFACE 
		//	(TYPE 'IMixer' GIVES MORE ARCHITECTURAL FLEXIBLITY THAN TYPE 'HandMixer')
		IMixer iMixer = new HandMixer ();
		
		// USE
		iMixer.doMixing();
		Debug.Log ("iMixer: " + iMixer);
		
		
	}