Esempio n. 1
0
        private void BtnCalcul_Click(object sender, EventArgs e)
        {
            try
            {
                Fraction fraction1 = new Fraction(Convert.ToInt32(txbFrac1Num.Text),
                                                  Convert.ToInt32(txbFrac1Den.Text));

                Fraction fraction2 = new Fraction(Convert.ToInt32(txbFrac2Num.Text),
                                                  Convert.ToInt32(txbFrac2Den.Text),
                                                  new BeautifierInterfaceParenthesis());

                Fraction fraction3 = new Fraction(Convert.ToInt32(txbFrac3Num.Text),
                                                  Convert.ToInt32(txbFrac3Den.Text),
                                                  new BeautifierInterfaceLatex());

                Fraction fraction4 = new Fraction(Convert.ToDecimal(txbFrac4.Text));
                Fraction fraction5 = fraction1.Add(fraction2);
                Fraction fraction6 = fraction1.Add(fraction2);
                Fraction fraction7 = fraction6.Sub(fraction3);

                lblResult1.Text = fraction1.ToString();
                lblResult2.Text = fraction2.ToString();
                lblResult3.Text = fraction3.ToString();
                lblResult4.Text = fraction1.ToString() + " + " + fraction3.ToString() + " = " + fraction5.ToString();
                lblResult5.Text = fraction1.ToString() + " + " + fraction2.ToString() + " - " + fraction3.ToString() + " = " + fraction7.ToString();
                lblResult6.Text = fraction4.ToString();
            }
            catch (Exception)
            {
                MessageBox.Show("Fractions can not be empty");
            }
        }
Esempio n. 2
0
        public void AdditionIdentity()
        {
            var x = new Fraction(1, 2);
            var y = x.Add(new Fraction(0, 1));

            Assert.Equal(new Fraction(1, 2), y);

            var z = x.Add(new Fraction(0, 2));

            Assert.Equal(new Fraction(1, 2), z);
        }
        public void TestAddingFractions()
        {
            var frac1   = new Fraction(-1, 8);
            var result1 = frac1.Add(new Fraction(5, 8));

            Assert.AreEqual("1/2", result1.ToString());
            var result2 = frac1.Add(new Fraction(2, 8));

            Assert.AreEqual("1/8", result2.ToString());
            var result3 = frac1 + new Fraction(-13, 8);

            Assert.AreEqual("-7/4", result3.ToString());
        }
Esempio n. 4
0
        public void Fraction_Add_Five_OneFourth()
        {
            Fraction five      = new Fraction(5);
            Fraction oneFourth = new Fraction(1, 4);

            Assert.True(five.Add(oneFourth) == new Fraction(21, 4));
        }
Esempio n. 5
0
        public void Fraction_Add_NegativeDenominator_One_Two()
        {
            Fraction one = new Fraction(1, -1);
            Fraction two = new Fraction(2);

            Assert.True(one.Add(two) == new Fraction(1));
        }
Esempio n. 6
0
        public void Fraction_Add_One_Two()
        {
            Fraction one = new Fraction(1);
            Fraction two = new Fraction(2);

            Assert.True(one.Add(two) == new Fraction(3));
        }
Esempio n. 7
0
        public void Fraction_Add_OneFourth_SevenEighths()
        {
            Fraction oneFourth    = new Fraction(1, 4);
            Fraction sevenEighths = new Fraction(7, 8);

            Assert.True(oneFourth.Add(sevenEighths) == new Fraction(9, 8));
        }
Esempio n. 8
0
    public void TestAddition()
    {
        Fraction testFractionOne = new Fraction(1, 2);
        Fraction testFractionTwo = new Fraction(1, 4);

        //Fraction expectedResults = new Fraction (3, 4);

        Fraction actualResults = new Fraction();

        //This adds the fractions but doesn't reduce them
        Fraction actualResult = actualResults.Add(testFractionOne, testFractionTwo);

        float actualNumerator   = actualResult.Numerator;
        float actualDenominator = actualResult.Denominator;


        // int expectedNumerator = 3;
        // int expectedDenominator = 4;

        //Check the actual maths (but not the reducing) works
        double expectedAnswer = 0.75;
        double actualAnswer   = actualNumerator / actualDenominator;

        //Assert.AreSame(expectedResults, actualResults);
        // Assert.AreEqual(expectedNumerator, actualNumerator);
        // Assert.AreEqual(expectedDenominator, actualDenominator);

        Assert.AreEqual(expectedAnswer, actualAnswer);
    }
Esempio n. 9
0
        public void WholeNumberAddWholeNumber_ReturnsFraction()
        {
            Fraction a      = new Fraction("3");
            string   result = a.Add(new Fraction("2")).ToString();

            Assert.AreEqual(result, "5");
        }
Esempio n. 10
0
        public void MixedFractionAddNegativeProperFraction_ReturnsMixedFraction()
        {
            Fraction a      = new Fraction("3_3/4");
            string   result = a.Add(new Fraction("-2/4")).ToString();

            Assert.AreEqual(result, "3_1/4");
        }
Esempio n. 11
0
        public void MixedFractionAddWholeNumber_ReturnsMixedFraction()
        {
            Fraction a      = new Fraction("3_3/4");
            string   result = a.Add(new Fraction("3")).ToString();

            Assert.AreEqual(result, "6_3/4");
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            Fraction first  = new Fraction(4, 3);
            Fraction second = new Fraction(2, 3);

            Console.WriteLine(first.GetRealValue());
            Fraction add = new Fraction();

            add = first.Add(second);
            Console.WriteLine(add.GetDisplayString());
            add.Simplify();
            Fraction multiply = new Fraction();

            multiply = first.Multiply(second);
            Console.WriteLine(multiply.GetDisplayString());
            multiply.Simplify();

            Fraction Input = new Fraction();

            Input.Numerator   = int.Parse(Console.ReadLine());
            Input.Denominator = int.Parse(Console.ReadLine());
            Console.WriteLine(Input.GetDisplayString());
            Input.Simplify();
            Console.ReadLine();
        }
Esempio n. 13
0
        public void Fraction_Add_OneHalf_OneThird()
        {
            Fraction oneHalf  = new Fraction(1, 2);
            Fraction oneThird = new Fraction(1, 3);

            Assert.True(oneHalf.Add(oneThird) == new Fraction(5, 6));
        }
Esempio n. 14
0
        public void Fraction_Add_TenFifths_TwentyTens()
        {
            Fraction tenFifths  = new Fraction(10, 5);
            Fraction twentyTens = new Fraction(20, 10);

            Assert.True(tenFifths.Add(twentyTens) == new Fraction(4));
        }
    void SetupFloor(int x, int z)
    {
        initialSetupCompleted = true;
//		Debug.Log("setting up lfoor;"+x+","+z);
//		foreach(MatrixFloorSquare mfs in squares){
//			Destroy(mfs.gameObject);
//		}
        squares = new GameObject[x, z];
        sizeX   = x;
        sizeZ   = z;
        Fraction f = new Fraction(1, 1);

        for (int i = 0; i < x; i++)
        {
            for (int j = 0; j < z; j++)
            {
                GameObject q = (GameObject)Instantiate(numberFlowerPrefab);
//				LevelBuilderObjectManager.inst.AddToPlacedObjects(SceneSerializationType.Instance,q.GetComponent<UserEditableObject>());
                q.transform.rotation = transform.rotation;
                q.transform.position = transform.position + transform.right * j * gridScale + transform.forward * i * gridScale + Vector3.up * .03f;                 //new Vector3(transform.i*gridScale,0.3f,j*gridScale);
                q.transform.parent   = transform;
                q.GetComponentInChildren <NumberInfo>().SetNumber(f);
                squares[i, j] = q;
                f             = Fraction.Add(new Fraction(1, 1), f);
            }
        }
    }
    public void OnReceivedNumber(Collider other)
    {
        if (finished)
        {
            // commented Debug.Log ("finisheD");
            return;
        }
        if (recTimer > 0)
        {
//			// commented Debug.Log ("rectimer");
            return;
        }

        ResourceNumber rn = other.GetComponent <ResourceNumber>();

        if (rn)
        {
            recTimer = 1f;

            NumberInfo ni = other.GetComponent <NumberInfo>();
            totalChargeCollected = Fraction.Add(ni.fraction, totalChargeCollected);

            charge.Add(other.gameObject);
            GrabNewNumber(other.gameObject, ni);
            if (Fraction.AbsGreater(totalChargeCollected, maxCharge))
            {
                StartCoroutine(OverfillAndEmpty());
//				EmptyBattery();
            }
            else
            {
            }
        }
    }
Esempio n. 17
0
        public void Addition()
        {
            var x = new Fraction(1, 2);
            var y = x.Add(new Fraction(1, 3));

            Assert.Equal(new Fraction(5, 6), y);
        }
Esempio n. 18
0
        public void Fraction_Add_WholeNumbers()
        {
            Fraction four = new Fraction(4);
            Fraction nine = new Fraction(9);

            Assert.True(four.Add(nine) == new Fraction(13));
        }
Esempio n. 19
0
        public void Fraction_Add_SevenFourths_FourFifths()
        {
            Fraction sevenFourths = new Fraction(7, 4);
            Fraction fourFifths   = new Fraction(4, 5);

            Assert.True(sevenFourths.Add(fourFifths) == new Fraction(51, 20));
        }
Esempio n. 20
0
        public void AddTest()
        {
            var    f         = new Fraction(4, 8);
            var    f2        = new Fraction(10, 8);
            var    res       = f.Add(f2);
            string resString = res.ToString();

            Assert.AreEqual("680/64", resString.Replace(" ", ""));
        }
Esempio n. 21
0
        public void Sum1_2and1_2return4_4()
        {
            //arrange
            Fraction expected = new Fraction(-1, 2);

            //act
            Fraction a = new Fraction(1, -1);
            Fraction b = new Fraction(1, 2);
            Fraction c = Fraction.Add(a, b);

            //assert
            Assert.AreEqual(expected, c);
        }
    void Update()
    {
        if (LevelBuilder.inst.levelBuilderIsShowing)
        {
            return;
        }
        if (active)
        {
            t -= Time.deltaTime;
            if (t < 0)
            {
                t = checkInterval;
                totalCollected = new Fraction(0, 1);
                foreach (Animal_Sheep sheep in sheepsInside)
                {
                    totalCollected = Fraction.Add(totalCollected, sheep.fraction);
                }
                if (Fraction.Equals(totalCollected, sheepNeeded))
                {
                    AudioManager.inst.PlayItemGetSound();
                    transform.root.GetComponentInChildren <ResourceDrop>().DropResource();
                    active = false;
                    PlayerNowMessage.inst.Display("You did it! You collected exactly " + sheepNeeded.ToString() + " sheep.", Player.inst.transform.position);
                }
            }
        }
        if (active && !LevelBuilder.inst.levelBuilderIsShowing && !optout)
        {
            userErrorCheckInterval -= Time.deltaTime;
            if (userErrorCheckInterval < 0)
            {
                userErrorCheckInterval = 20;
                if (!PlayerDialogue.inst.showing)
                {
                    Fraction            totalAvailable = new Fraction(0, 1);
                    List <Animal_Sheep> sheepsLeft     = new List <Animal_Sheep>();
                    sheepsLeft.AddRange(FindObjectsOfType <Animal_Sheep>());
//					foreach(Animal_Sheep sheep in sheepsLeft){
//						totalAvailable = Fraction.Add(totalAvailable,sheep.fraction);
//					}
                    if (sheepsLeft.Count == 0 && FindObjectsOfType <LevelMachineSheepConverter>().Length == 0 && thereWereSheepOnStartup && !Fraction.Equals(totalCollected, sheepNeeded))
                    {
                        // TODO: we shouldn't be assigning delegates to player dialogue if it's already showing, so we should pass delegate targets (list) into the ShowPlayerDialogue function and handle it there
                        PlayerDialogue.inst.ShowPlayerDialogue("I'm counting sheep, and there are none left! Do you want to restart?", "Uh oh..", sheepIcon);
                        PlayerDialogue.inst.playerPressedOKDelegate     += PlayerWantedToRestart;
                        PlayerDialogue.inst.playerPressedCancelDelegate += PlayerCanceled;
                    }
                }
            }
        }
    }
Esempio n. 23
0
    void OnTriggerEnter(Collider other)
    {
        if (LevelBuilder.inst.levelBuilderIsShowing)
        {
            return;
        }
        NumberInfo ni = other.GetComponent <NumberInfo>();

        if (ni && ni.fraction.denominator == 1 && !ni.GetComponent <BlobNumber>())
        {
            if (blobNumbers.Contains(ni))
            {
                return;
            }
            else
            {
                List <NumberInfo> numsToAdd = new List <NumberInfo>();
                bool allowedToAddThisNumber = false;

                foreach (NumberInfo n2 in blobNumbers)
                {
                    Fraction result = Fraction.Add(ni.fraction, n2.fraction);

                    if (type == SnailType.Factors && n2.fraction.IsMultipleOf(ni.fraction) && !allowedToAddThisNumber)
                    {
                        allowedToAddThisNumber = true;

//							break;
                    }
                    else if (type == SnailType.Multiples && ni.fraction.IsMultipleOf(n2.fraction) && !allowedToAddThisNumber)
                    {
                        allowedToAddThisNumber = true;

//							break;
                    }


//					}
                }
                if (allowedToAddThisNumber)
                {
                    numsToAdd.Add(ni);
                }
                foreach (NumberInfo numToAdd in numsToAdd)
                {
                    AddNumberToBlob(numToAdd);
                }
            }
        }
    }
    bool ChildrenSumEqualsZero()
    {
        Fraction total = new Fraction(0, 1);

        foreach (NumberInfo ni in GetComponentsInChildren <NumberInfo>())
        {
            if (ni != spikeyCounter)
            {
                total = Fraction.Add(ni.fraction, total);
            }
        }
        spikeyCounter.SetNumber(total);
        return(total.numerator == 0);
    }
Esempio n. 25
0
        public void Add_Integers()
        {
            //Arrange
            var frac1    = new Fraction(2, 3);
            var n        = 2;
            var expected = new Fraction(8, 3);

            //Act
            frac1.Add(n);

            //Assert
            Assert.AreEqual(expected.Numerator, frac1.Numerator);
            Assert.AreEqual(expected.Denominator, frac1.Denominator);
        }
Esempio n. 26
0
        public void Add_Regular_1()
        {
            //Arrange
            var frac1    = new Fraction(1, 2);
            var frac2    = new Fraction(1, 2);
            var expected = new Fraction(1, 1);

            //Act
            frac1.Add(frac2);

            //Assert
            Assert.AreEqual(expected.Numerator, frac1.Numerator);
            Assert.AreEqual(expected.Denominator, frac1.Denominator);
        }
Esempio n. 27
0
        public void Add_Decimals_Mixed()
        {
            //Arrange
            var frac1    = new Fraction(0.1m, 0.5m);
            var frac2    = new Fraction(0.45m, 0.25m);
            var expected = new Fraction(2, 1);

            //Act
            frac1.Add(frac2);

            //Assert
            Assert.AreEqual(expected.Numerator, frac1.Numerator);
            Assert.AreEqual(expected.Denominator, frac1.Denominator);
        }
Esempio n. 28
0
        public void Add_Decimals_InNumertor()
        {
            //Arrange
            var frac1    = new Fraction(2.1m, 1);
            var frac2    = new Fraction(3.3m, 1);
            var expected = new Fraction(5.4m, 1);

            //Act
            frac1.Add(frac2);

            //Assert
            Assert.AreEqual(expected.Numerator, frac1.Numerator);
            Assert.AreEqual(expected.Denominator, frac1.Denominator);
        }
Esempio n. 29
0
        public void Add_IntegersAsFraction()
        {
            //Arrange
            var frac1    = new Fraction(2, 1);
            var frac2    = new Fraction(3, 1);
            var expected = new Fraction(5, 1);

            //Act
            frac1.Add(frac2);

            //Assert
            Assert.AreEqual(expected.Numerator, frac1.Numerator);
            Assert.AreEqual(expected.Denominator, frac1.Denominator);
        }
Esempio n. 30
0
    virtual public void Eat(GameObject o)
    {
        if (!o)
        {
            LoseTarget("no obj");
            return;
        }

        NumberInfo ni = o.GetComponent <NumberInfo>();

        if (!ni)
        {
            LoseTarget("no ni");
            return;
        }
        if (ni.usedThisFrame)
        {
            LoseTarget("ni used");
            return;
        }
        ni.usedThisFrame = true;
        ni.NotifyDestroyer(this.gameObject);         // let numberinfo know who is eating it.
        Fraction result = Fraction.Add(this.fraction, ni.fraction);

        if (result.numerator == 0)
        {
            Debug.Log("Result of  animal " + this.fraction + " and ate:" + ni.fraction + " was zero!");
            foreach (IDestroyedByPlayer dp in gameObject.GetComponents(typeof(IDestroyedByPlayer)))
            {
                dp.DestroyedByPlayer();
            }
        }
        base.Eat(ni);
//		Sprite icon = ni.GetComponent<UserEditableObject>().icon;

//		justAteFX.transform.parent = transform;

        if (AnimalIsFrogType())
        {
            float p = Random.Range(0.75f, 1.1f);
            AudioManager.inst.PlayMunch(transform.position, 1, p);           // frogs have a quieter munch
        }
        else
        {
            AudioManager.inst.PlaySheepMunch(transform.position);
        }
        LoseTarget("ate");
    }