CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-deep-eql

Improved deep equality testing for Node.js and the browser with support for complex types and circular references.

Overall
score

96%

Overview
Eval results
Files

task.mdevals/scenario-8/

Function Signature Validator

Build a function signature validator that compares actual function calls against expected signatures to verify correct function invocation patterns.

Overview

Create a utility that validates whether functions are being called with the correct argument patterns. The validator should compare the actual arguments passed to a function against expected argument patterns, handling the special nature of JavaScript's arguments object.

Requirements

Core Functionality

Create a validateSignature(actual, expected) function that:

  • Accepts actual: the arguments object from a real function call
  • Accepts expected: an array representing the expected argument pattern
  • Returns true if the arguments match the pattern (element-by-element comparison)
  • Returns false otherwise

Validation Rules

  • Compare each argument element against the corresponding expected element using deep equality
  • The number of arguments must match the expected length exactly
  • Nested objects/arrays within arguments should be compared deeply
  • Note: An arguments object itself should NOT be directly compared to arrays as equal objects (they are different types), but their individual elements should be compared

Test Cases

  • When a function is called with arguments (5, "hello", {x: 1}), it should match the expected pattern [5, "hello", {x: 1}] @test
  • When a function is called with arguments (1, 2), it should NOT match the expected pattern [1, 2, 3] (different lengths) @test
  • When a function is called with arguments (1, 2), those arguments should NOT be considered equal to the plain array [1, 2] (arguments vs array distinction) @test
  • When a function is called with arguments ({a: {b: 2}}), it should match the expected pattern [{a: {b: 2}}] (deep comparison) @test

Implementation

@generates

API

/**
 * Validates whether function arguments match an expected signature pattern
 * @param {IArguments} actual - The arguments object from a function call
 * @param {Array} expected - The expected argument pattern as an array
 * @returns {boolean} True if arguments match the pattern, false otherwise
 */
function validateSignature(actual, expected) {
  // Implementation here
}

module.exports = { validateSignature };

Dependencies { .dependencies }

deep-eql { .dependency }

Provides deep equality comparison with support for arguments objects.

Install with Tessl CLI

npx tessl i tessl/npm-deep-eql

tile.json