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 6662467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:23:33+00:00 2026-05-26T02:23:33+00:00

How do I compare the tree structure inside an object task with the obj_after

  • 0

How do I compare the tree structure inside an object task with the obj_after tree, without having to actually compare individual nodes in the tree. (one is an instance of a class i.e. with instance methods and the other has no functions just data).

Please read below to understand my exact problem (not so clear from the above).

I am writing a script that builds a GUI based on a js object tree. I am using coffeescript for this.

I would like to create a class that takes a json, and build the tree.

window.GuiTree = class GuiTree
    constructor:(json_GUI_tree)->

But the problem I am having is in testing this. I would like to add methods to this class like ‘add_node’. That adds a new node to the GuiTree.

So I try this in Jasmine.

obj_before =
  1:
    type:"text" 
    name:"task"
    label:"Task"
  2:
    type:"subsection"
    sections:
      3:
        4:
          type:"text" 
          name:"subtask"
          label:"Subtask"   


obj_after =
  1:
    type:"text" 
    name:"task"
    label:"Task"
  2:
    type:"subsection"
    sections:
      3:
        4:
          type:"text" 
          name:"subtask"
          label:"Subtask"   
        5:
          type:"text" 
          name:"subtask"
          label:"Subtask"

Where I have added the task 5 to the Gui tree

And I would like to test it like this

task = new GuiTree(obj_before)
expect(task.add(3, node_5)).givesNewTree(obj_after)

The matcher ‘givesNewTree’ is a custom matcher.

The problem is here !! how do I compare the tree structure inside the object task with the obj_after tree, without having to actually compare individual nodes in the tree. (one is )

To me it looks like lots of error prone code to write to compare the trees. So I may need to write tests to test. Is there a smarter way.

  • 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-26T02:23:34+00:00Added an answer on May 26, 2026 at 2:23 am

    What you’re looking for is an implementation of deep equivalence. They’re not necessarily error prone, in fact there are several known implementation, the most well known is QUnit’s deepEqual implementation. Here’s another. Granted it’s a quite complicated algorithm.

    Your could of course also define a .equals (or similarly named) method in your GuiTree class that compares two instances in a simpler way based on what you already know is significant about them, but I would try existing deep equal algorithms first since you might be able to import previously written code that you already know is correct.

    A hackish alternative is to do JSON.stringify() on both objects and expect the resulting JSON encoded strings to be equal, but I suspect that could lead to various problems with circular references and the like, but it might get you started.

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

Sidebar

Related Questions

In the tree class I'm suppose to compare two node, for you know searching
I'm currently working on a tree structure of nodes where each node should be
Is there an easy way to compare the file tree of an old git
I would like to compare a screenshot of one application (could be a Web
How does Trie and B+ tree compare for indexing lexicographically sorted strings [on the
My data structures class is working with trees. We are implementing a 3-ary tree,
So I'm attempting to utilize a generic compare functor in my utility class. I
I am writing a Generic Binary Search Tree. I need to compare two generic
I was just doing some research on RedBlack Tree. I knew that SortedSet class
Compare String.Format(Hello {0}, World); with Hello {0}.Format(World); Why did the .Net designers choose a

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.