question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Arguments Optional] Current test cases allow for unintended solutions to pass

See original GitHub issue

Describe your problem and how to reproduce it: On the Intermediate Algorithm Scripting: Arguments Optional challenge, the only two happy path test cases – addTogether(2, 3) and addTogether(2)(3), both expect a return value of 5. All other test cases expect a return value of undefined. Because there are no other happy path test cases, it’s possible to construct a passing solution that doesn’t add inputs together, but simply returns 5 when the inputs are valid numbers (pasted below). Another set of happy path test cases could help prevent this sort of unintended solution from passing.

// passes tests without performing addition
function addTogether(x, y) {
  if (y) {
    return returnFive(x, y);
  }
  return curriedReturnFive(x);
}

function returnFive(x, y) {
  if (!areNumbers(x, y)) {
    return;
  }
  return 5; // just 5 satisfies current tests
}

function curriedReturnFive(x) {
  if (!isNumber(x)) {
    return;
  }
  return function(y) {
    return returnFive(x, y);
  }
}

function areNumbers(...args) {
  return args.every(isNumber);
}

function isNumber(x) {
  return typeof x === 'number';
}

Add a Link to the page with the problem: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional

If possible, add a screenshot here (you can drag and drop, png, jpg, gif, etc. in this box): image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
rajat641commented, May 16, 2020

Hi @Ieahleen @moT01 @Sky020 , I hope you’re good. I have raised a PR for this Issue with adding 2 extra test cases. Let me know if more test cases are to be added or something is not right. Thanks a lot guys for the opportunity.

1reaction
rajat641commented, May 13, 2020

@Sky020 - Please allow me to work on this. I am new to open source and it would be great If I can work on this .

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Write Test Cases: The Ultimate Guide with Examples
A test case is a set of instructions on “HOW” to validate a particular test objective/target, which, when followed will tell us if...
Read more >
Using Python Optional Arguments When Defining Functions
In this tutorial, you'll learn about Python optional arguments and how to define functions with default values. You'll also learn how to create...
Read more >
Optional Method Parameters - DZone
We're done with the arguments against Optional method parameters that I found online. Let me augment those with some of my recent reasoning....
Read more >
dotnet test command - .NET CLI | Microsoft Learn
Sdk is the test host, xunit is the test framework. And xunit.runner.visualstudio is a test adapter, which allows the xUnit framework to work ......
Read more >
Function Argument Validation - MATLAB & Simulink
arguments Block Syntax. Functions define argument validation in optional code blocks that are delimited by the keywords arguments and end . If used,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found