Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7024407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:50:08+00:00 2026-05-27T23:50:08+00:00

I’m trying to test an application that takes three arguments as input (side A,

  • 0

I’m trying to test an application that takes three arguments as input (side A, side B, side C) and calculates the triangle is isoscele (two sides are equal), scalene (none of the sides are equal) or equilateral (all sides are equal).

Below is some code from the unit-testing i’m working on. In this case i’m testing that the application tells the user that the triangle is isoscele, and my question here is what I should have after Assert in this case? AreNotSame works for scalene, AreSame works for equilateral, but what works here? Thanks in advance.

public void isIsoscelesTest()
{
    Triangle target = new Triangle(5.0, 5.0, 2.0); // TODO: Initialize to an appropriate value
    bool expected = true; // TODO: Initialize to an appropriate value
    bool actual;
    actual = target.isIsosceles();
    Assert.AreNotSame(expected, actual);
}

From the application…

public bool isIsosceles()
{
    if (uniqueSides() == 2)
        return true;
    return false;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:50:09+00:00Added an answer on May 27, 2026 at 11:50 pm

    Ideally you should create one test per test-case, so in your example, I’d probably have

    [Test]
    public void isIsoscelesTest()     
    { 
        var triangle = new Triangle(5.0, 5.0, 2.0); 
        Assert.That(triangle.isIsoceles(), Is.True);
        Assert.That(triangle.isEquilateral(), Is.False);
        Assert.That(triangle.isScalene(), Is.False);
    }
    

    as well as

    [Test]
    public void isScaleneTest()     
    { 
        var triangle = new Triangle(3.9, 5.0, 2.0); 
        Assert.That(triangle.isIsoceles(), Is.False);
        Assert.That(triangle.isEquilateral(), Is.False);
        Assert.That(triangle.isScalene(), Is.True);
    }
    

    and

    [Test]
    public void isEquilateralTest()     
    { 
        var triangle = new Triangle(3.9, 3.9, 3.9); 
        Assert.That(triangle.isIsoceles(), Is.False);
        Assert.That(triangle.isEquilateral(), Is.True);
        Assert.That(triangle.isScalene(), Is.False);
    }
    

    Personally I would assert in each test that it is a specific type, but not the other two types, however you could also separate these into separate test cases (then it gets verbose though).

    In the above example we have some (nearly) duplicate code which could be factored out into a helper method if so desired. In addition, we’re only testing three seperate combinations of variables (side lengths). What if you put any other values in there though? Ok fine we can’t test for everything but it gives you a general idea of the shortcomings of unit tests with numerical values.

    Finally, be advised that the == operator when using double or floating precision doesn’t always produce true. For instance, try this code:

    [Test]
    public void DoublePrecisionRoundingTest()
    {
       double aValue = 1.2345678;
       Assert.That(aValue + double.Epsilon, Is.EqualTo(aValue)); // passes! Should fail
    }
    

    The reason for this is that in double-precision the rounding error can cause some numerical operations to get annihilated. As a workaround (and this affects your triangle code), you should always test for “near enough” with double or float variables.

    E.g. Instead of this inside your Triangle.uniqueSides method:

    if (aDouble == otherDouble) 
    

    it is advisable (but not always necessary) to use this

    if(Math.Abs(aDouble - otherDouble) < EPSILON)
    

    where EPSILON is a really small value.

    Best regards,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.