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

  • SEARCH
  • Home
  • 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 7719001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:18:21+00:00 2026-06-01T03:18:21+00:00

I have a deep tree structure built with lists, containing lists and floats. I

  • 0

I have a deep tree structure built with lists, containing lists and floats.
I want to make assertions on such a structure, without being able to use a delta for the floats. My problem is, using the output from the failed assert is not enough, as one or two extra decimals are needed. I have to guess these decimals to proceed.

using System.Collections;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

    namespace TestAssertLab
    {
        public class List : ArrayList {
            public List(params object[] list) {
                AddRange(list);
            }
            public override bool Equals(object other) {
                List l = other as List;
                if (l != null) {
                    if (Count != l.Count) return false;
                    return !l.Cast<object>().Where((t, i) => !this[i].Equals(t)).Any();
                }
                return false;
            }
            public override string ToString() {
                string s = this.Cast<object>().Aggregate("", (current, item) => current + (item + ","));
                return "[" + s.TrimEnd(',') + "]";
            }
        }

        [TestClass]
        public class AssertLab
        {
             public List z(params object[] l) {
                  return new List(l);
             }
            [TestMethod]   
            public void TestFails() {
                List expected = z(0.1428571f, z(101, 102));
                List actual =   z(1/7.0f,     z(101, 102));
                Assert.AreEqual(expected, actual);  
                // output: Assert.AreEqual failed. Expected:<[0.1428571,[101,102]]>. Actual:<[0.1428571,[101,102]]>.
            }
            [TestMethod]
            public void TestOK()
            {
                List expected = z(0.142857143f, z(30101, 30102));
                List actual = z(1 / 7.0f, z(30101, 30102));
                Assert.AreEqual(expected, actual);
            }
        }
    }
  • 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-06-01T03:18:22+00:00Added an answer on June 1, 2026 at 3:18 am

    You could cast them to decimal:

    (Decimal) 0.1428571f == (Decimal)(1 / 7.0f)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tree structure that can be n-levels deep, without restriction. That means
I have a tree data structure that is L levels deep each node has
I have a deep structure that I would like to display as a tree
I have an XML structure that is 4 deep: <?xml version=1.0 encoding=utf-8?> <EmailRuleList xmlns:xsd=EmailRules.xsd>
I have a basic tree structure of entities. The tree can be a maximum
I have a deep tree and for user it's difficult to distinguish the levels.
I want to open a file that is somewhere deep in my project tree.
I have a tree structure in MySQL using a parent_id field for each node.
I have an xml sitemap structured like a document tree, such that it looks
I have a relatively deep object tree in C# that needs to be initialized

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.