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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:26:34+00:00 2026-06-11T11:26:34+00:00

My Ray module: define([‘Util’, ‘Vector3f’], function (Util, Vector3f) { var Ray = {} Ray.o

  • 0

My Ray module:

define(['Util', 'Vector3f'], function (Util, Vector3f) {
  var Ray = {}
  Ray.o = null;
  Ray.d = null;
  Ray.depth = 0;
  Ray.mint = 0.03;
  Ray.maxt = null;
  return Ray;
});

My unit test:

describe(".moveAlong(Number t)", function(){
  it("returns a point at distance t in the direction of the ray", 
  function(){
    expect(4).toBe(null); //unimplemented unit test always fails
  });
});

Ray.o is the ray’s origin. Ray.d is the ray’s direction. I want Ray.moveAlong(t) to return a point q such that q = o + d*t.

My understanding of unit-testing is that if I actually include my Vector3f module in my unit-test so that I can give the Ray an origin and a direction, what I’m actually doing it integration-testing. But I’ll need the add() and mulScalar() methods from my Vector3f module in order to calculate ray.d + ray.d*t in moveAlong(t).

What are my options for handling my Vector3f-dependency here? I don’t see how I can reasonably stub it out, but stubbing out dependencies and testing only one method at a time is the point of unit-testing.

  • 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-11T11:26:35+00:00Added an answer on June 11, 2026 at 11:26 am

    Unit-testing options:

    First option:
    Just pass in Vector3f objects for Ray.o, Ray.d

    Pros:
    – Easy.

    Cons:
    – Preserves dependency in tests.
    – Updates to components not under this test (Vector3f) may require updates to this test.

    Second Option:
    Create stub Vector3fs, each implementing only the add(Vector3f v), mulScalar(Number t) methods of the Vector3f module. This is super easy in Javascript, because references are typeless, and any object that has the right methods may substitute for the “right” object. Which makes me think that trying to shoe-horn OOP into this project is a bad idea, but I’m not really sure how else to approach this and that’s a topic for another question.

    Pros:
    – Breaks dependency between Ray and Vector3f in testing code, so that further changes to Vector3f will not result in Ray failing unit tests, which cuts down on the number of failed tests to be inspected if something breaks Vector3f.

    Cons:
    – More code in tests.
    – If Vector3f is altered in a way that lets it pass all its unit tests, but breaks functionality of Ray, then we will not see it in the Ray unit tests, either, because the dependency on Vector3f has been broken.

    I’m not sure that last con is a problem – if Vector3f is passing all its unit tests, then it is obeying its contract with the other components of the system, so we shouldn’t ever see a situation where Vector3f’s tests all pass but it causes other components break. Further, that’s an integration-level issue, not a unit-level issue.

    I think the second option is the way to go.

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

Sidebar

Related Questions

I'm doing ray casting in the fragment shader. I can think of a couple
I’ve completely stuck with camera in ray tracing. Please, take a look at my
I'm using the Custom Picker by ray, when I press a button a picker
I have to implement simple ray tracing algorithm, but I can not figure out
I am currently trying to understand the ray tracer developed by Kevin Beason (smallpt:
I've got an array of names: $names = array('ray'=>0,'bob'=>1,'sue'=>2,'jeff'=>3); Then I have a table
New developer here,Im using the Custom Image Picker by ray wenderlich. But what I
I have been trying to work with the Projector and Ray classes in order
can someone point me to some methods for perspective ray casting. I have seen
I wish to determine the intersection point between a ray and a box. The

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.