Example #1
0
    private IEnumerator MoveToCauldron()
    {
        /* Turn off animations, as this is a throwing potion */
        playAnimations = false;
        animator.Rebind();
        animator.enabled = false;
        /* Trigger a throw sound effect */
        AudioManager.Instance.PlayEffect(AudioManager.SoundEffects.PotionThrow);
        Vector2    destination = cauldron.gameObject.transform.position;
        Quaternion rotation    = Quaternion.Euler(new Vector3(0f, 0f, Random.Range(1f, 30f)));

        foreach (Vector2 position in CoolStuff.PositionOverParabola(startPosition, cauldron.GetPotionArcMidpoint(), destination, .5f))
        {
            transform.position = position;
            transform.Rotate(rotation.eulerAngles);
            yield return(null);
        }

        /* Trigger a bottle break sound effect */
        AudioManager.Instance.PlayEffect(AudioManager.SoundEffects.PotionBreak);
        /* The potion is now at the cauldron */
        cauldron.AddPotion(this);
        /* Destroy the duplicate potion */
        Destroy(this.gameObject);
    }
Example #2
0
        public void TestImprovedOutVariable()
        {
            CoolStuff coolStuff  = new CoolStuff();
            string    parsedText = coolStuff.ParseStringAsInteger("88");

            Assert.AreEqual(parsedText, "88");
        }
Example #3
0
        public void TestPatternMatching()
        {
            List <object> listOfNumbers = new List <object>();

            listOfNumbers.Add(2);
            listOfNumbers.Add(new List <int>()
            {
                1, 8, 1, 10
            });
            listOfNumbers.Add(3);
            listOfNumbers.Add(-30);
            listOfNumbers.Add(0);
            int sumOfPositive = CoolStuff.SumPositiveNumbers(listOfNumbers);

            Assert.AreEqual(sumOfPositive, 25);
        }
Example #4
0
        public void SimpleTupleTests()
        {
            var p = new TuplePoint(3.14, 2.71);

            (double X, double Y) = p;
            Assert.AreEqual(X, 3.14);
            Assert.AreEqual(Y, 2.71);

            var unamed = ("one", "two");

            Assert.AreEqual(unamed.Item1, "one");
            var namedTuple = (First : "one", Second : "two");

            Assert.AreEqual(namedTuple.First, "one");
            Assert.AreEqual(namedTuple.Second, "two");

            var sum          = 12.5;
            var count        = 5;
            var accumulation = (count, sum);

            Assert.AreEqual(accumulation.sum, sum);

            var localVariableOne = 5;
            var localVariableTwo = "some text";

            var testTuple = (explicitFieldOne : localVariableOne, explicitFieldTwo : localVariableTwo);

            Assert.AreEqual(testTuple.explicitFieldOne, localVariableOne);

            var left  = (a : 5, b : 10);
            var right = (a : 5, b : 10);

            Assert.AreEqual(left, right);

            // Lifted conversion
            (int a, int b)? nullableRightTuple = right;
            Assert.AreEqual(nullableRightTuple, right);

            // Nested tuples
            (int, (int, int))nestedTuple = (1, (2, 3));
            Assert.AreEqual(nestedTuple, (1, (2, 3)));

            // The 'arity' and 'shape' of all these tuples are compatible.
            // The only difference is the field names being used.
            var unnamed        = (42, "The meaning of life");
            var anonymous      = (16, "a perfect square");
            var named          = (Answer : 42, Message : "The meaning of life");
            var differentNamed = (SecretConstant : 42, Label : "The meaning of life");

            unnamed = named;
            named   = unnamed;

            // 'named' still has fields that can be referred to as 'Answer', and 'Message':
            Assert.AreEqual(named.Answer, 42);
            Assert.AreEqual(named.Message, "The meaning of life");

            anonymous = unnamed;

            // named tuples.
            named = differentNamed;
            // The field names are not assigned. 'named' still has fields that can be referred to as 'Answer' and 'Message':
            Debug.WriteLine($"{named.Answer}, {named.Message}");

            // With implicit conversions:
            // int can be implicitly converted to long
            (long, string)conversion = named;
            Assert.AreEqual(conversion.Item1, 42L);

            double standardDeviation = CoolStuff.StandardDeviationWithTuple(new List <double>()
            {
                11d, 22d, 33d, 44d, 55d, 66d, 77d, 88d, 99d, 111d
            });

            Assert.IsTrue(standardDeviation > 22d);

            // Inferred tuple element names
            int    Id                = 5;
            string LookupName        = "CN0073893";
            var    testInferredTuple = (Id, LookupName); // element names are "Id" and "LookupName"
            var    sameAsTestTuple   = (Id, LookupName);

            Assert.AreEqual(testInferredTuple.Id, Id);
            Assert.AreEqual(testInferredTuple.LookupName, LookupName);
            Assert.AreEqual(testInferredTuple, sameAsTestTuple);
            Assert.IsTrue(testInferredTuple == sameAsTestTuple);
        }
Example #5
0
 public void TestDiscards()
 {
     var(_, _, _, pop1, _, pop2) = CoolStuff.QueryCityDataForYears("New York City", 1960, 2010);
     Assert.AreEqual(pop1, 7781984);
     Assert.AreEqual(pop2, 8175133);
 }