Making code suitable for unit tests

In this code the user presses a button cmdPythagoras which calls the FindAllTriples method.  How would I unit test this code?  The FindAllTriples method doesn't return a single value.

 private void cmdPythagoras_Click(object sender, EventArgs e)
        {

            FindAllTriples();
        }
        public void FindAllTriples()
        {
            try
            {
                List<Pythagoras> pt = new List<Pythagoras>();
                int Small = 0;
                int Med = 0;
                int Big = 0;
                CheckPrimes cp = new CheckPrimes();

                for (Small = 2; Small <= 100; Small++)

                {
                    for (Med = Small + 1; Med <= 1000; Med++)
                    {

                        {
                            for (Big = Small + 1; Big <= 1000; Big++)
                                if ((Small * Small) + (Med * Med) == (Big * Big))
                                {
                                    //Example using delegate
                                    myDelegate dg = new myDelegate(cp.CheckIfNumberIsPrime);
                                    Pythagoras p = new Pythagoras();
                                    p.Smallest = Small;
                                    p.Medium = Med;
                                    p.Biggest = Big;
                                    if (dg(Small) == true || dg(Med) == true || dg(Big) == true)
                                    {
                                        p.Comment = "At least one prime";
                                    }
                                    else if (cp.GCDRecursive(Small,
                                        Med) == 1 && cp.GCDRecursive(Small, Big) == 1 && cp.GCDRecursive(Med, Big) == 1)
                                    {
                                        p.Comment = "Numbers have no highest common factor";
                                    }
                                    else
                                    {
                                        p.Comment = "";
                                    }
                                    pt.Add(p);
                                }
                        }
                    }
                }
                using (StreamWriter sw = new StreamWriter(@"D:\Documents\MathsPrograms\Pythagoras.csv", false))
                {
                    foreach (Pythagoras p in pt)
                    {
                        sw.WriteLine(p.Smallest + "," + p.Medium + "," + p.Biggest + "," + p.Comment);

                    }
                    Environment.Exit(0);
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }
        }
        public Boolean CheckIfNumberIsPrime(int CheckThisNumber)
        {
            int Counter = 2;

                Counter = 2;
                //for (Counter = 2; Counter*Counter <= CheckThisNumber; Counter++)
                do
                {
                    if (CheckThisNumber % Counter == 0)
                    {
                        return false;
                    }
                    else
                    {

                    }
                    Counter += 1;
                } while (Counter * Counter < CheckThisNumber);
                if (Counter * Counter > CheckThisNumber)
                {
                    return true;
                }
                else
                {
                    return false;
                }

        }
public int GCDRecursive(int a, int b)
        {
            //article on http://www.vcskicks.com/euclidean-gcd.php
            if (a == 0)
                return b;
            if (b == 0)
                return a;

            if (a > b)
                return GCDRecursive(a % b, b);
            else
                return GCDRecursive(a, b % a);
        }
    }

Open in new window


I wrote this unit test for the GCDRecursive method.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MathsProg;
namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestHightestCommonDivisor()
        {
            int FirstInteger = 20;
            int secondInteger = 24;
            int expected = 4;
            CheckPrimes cp = new CheckPrimes();
            int actual=cp.GCDRecursive(FirstInteger, secondInteger);
            Assert.AreEqual(expected, actual);

        }
    }
}

Open in new window

AlHal2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Normally UI is the view in the Model-View-Controller (MVC), Model-View-ViewModel (MVVP) or Model-View-Presenter (MVP) architecture pattern.

These architecural patterns separate UI from logic. So that you can test the logic. Views are not tested with unit tests. Only the model or the controllor.

So you need a class CheckPrimes separate from your form and unit test.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlHal2Author Commented:
Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
unit testing

From novice to tech pro — start learning today.