Skip to content

Add clamp function with schema and unit tests#12

Open
mck wants to merge 1 commit intomainfrom
feat/math-clamp
Open

Add clamp function with schema and unit tests#12
mck wants to merge 1 commit intomainfrom
feat/math-clamp

Conversation

@mck
Copy link
Collaborator

@mck mck commented Jan 26, 2026

Implements a clamp function to constrain a value between minimum and maximum bounds. Includes TokenScript implementation, JSON schema definition, and comprehensive unit tests covering various edge cases and value types.

Implements a clamp function to constrain a value between minimum and maximum bounds. Includes TokenScript implementation, JSON schema definition, and comprehensive unit tests covering various edge cases and value types.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a general-purpose numeric clamp function with a TokenScript implementation, JSON schema, and unit tests to constrain values between minimum and maximum bounds.

Changes:

  • Adds clamp.tokenscript implementing numeric clamping via TokenScript’s min/max primitives.
  • Defines schema.json for the clamp function, including input/return types and illustrative examples.
  • Adds unit.test.ts with Vitest coverage for schema presence and clamping behavior for integers, negatives, and floating-point values and boundaries.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/schemas/functions/clamp/clamp.tokenscript Implements the clamp operation as min(max_val, max(min_val, value)) using TokenScript built-ins.
src/schemas/functions/clamp/schema.json Declares the clamp function’s schema, metadata, input array (value, min, max), return type, and example usages.
src/schemas/functions/clamp/unit.test.ts Verifies the function schema and runtime behavior across in-range, out-of-range, boundary, negative, and decimal inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants