techfeudalist on Nostr: Here’s a super simple example: To AI: Imagine a function that takes two integers ...
Here’s a super simple example:
To AI:
Imagine a function that takes two integers and adds them returns true if the sum is less than 100, else false, propose three tests
——-
AI might respond…
Sure, here are three test cases for such a function:
1. **Test Case 1: Two small numbers**
- Input: 5, 10
- Expected Output: True (because 5 + 10 = 15, which is less than 100)
2. **Test Case 2: Numbers summing up to exactly 100**
- Input: 60, 40
- Expected Output: False (because 60 + 40 = 100, which is not less than 100)
3. **Test Case 3: Large numbers exceeding 100**
- Input: 75, 50
- Expected Output: False (because 75 + 50 = 125, which is more than 100)
You'd want a range of test cases to ensure that the function behaves correctly for different kinds of inputs.
———
Now write the JS function and tests using Jest
—————
Certainly! Here's how you would write the first test for the function using Jest:
First, let's define the function (I'll name it `isSumLessThan100`):
```javascript
function isSumLessThan100(a, b) {
return a + b < 100;
}
```
Now, let's write a Jest test for it:
```javascript
const isSumLessThan100 = require('./path-to-your-function-file'); // Import the function
describe('isSumLessThan100', () => {
test('should return true for numbers summing to less than 100', () => {
const result = isSumLessThan100(5, 10);
expect(result).toBe(true);
});
});
```
Published at
2023-08-10 19:06:37Event JSON
{
"id": "9bf740e3a2be804176f1f55c91dfab70cc2ad26e2d5f5fec85c448a3296b0863",
"pubkey": "98a386c766ac9250f4ce1b500662fd08e4d464a1915743eedc83bd50521decac",
"created_at": 1691694397,
"kind": 1,
"tags": [
[
"e",
"2d5861ffb65ff467948170bed410870582998c51c7e6083eacbe7a27048249e4",
""
],
[
"e",
"039fa6ba1f7b89d222d4a90f6e20d4a1c18a1b8fbc0e6b302c6ea22590aa5575"
],
[
"p",
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"
],
[
"p",
"6e046c3791b5fcb46d50c96aa498a47d28b5b1544cefefb2f8a33ae1b6c231fc"
],
[
"p",
"000fee6e9bb874f48922a5915890edfbe1356fb4c4bc2bb51eea234bdfb258a5"
]
],
"content": "Here’s a super simple example:\n\nTo AI:\n\nImagine a function that takes two integers and adds them returns true if the sum is less than 100, else false, propose three tests\n\n——-\n\nAI might respond…\n\nSure, here are three test cases for such a function:\n\n1. **Test Case 1: Two small numbers**\n - Input: 5, 10\n - Expected Output: True (because 5 + 10 = 15, which is less than 100)\n\n2. **Test Case 2: Numbers summing up to exactly 100**\n - Input: 60, 40\n - Expected Output: False (because 60 + 40 = 100, which is not less than 100)\n\n3. **Test Case 3: Large numbers exceeding 100**\n - Input: 75, 50\n - Expected Output: False (because 75 + 50 = 125, which is more than 100)\n\nYou'd want a range of test cases to ensure that the function behaves correctly for different kinds of inputs.\n\n———\n\nNow write the JS function and tests using Jest\n\n—————\n\nCertainly! Here's how you would write the first test for the function using Jest:\n\nFirst, let's define the function (I'll name it `isSumLessThan100`):\n\n```javascript\nfunction isSumLessThan100(a, b) {\n return a + b \u003c 100;\n}\n```\n\nNow, let's write a Jest test for it:\n\n```javascript\nconst isSumLessThan100 = require('./path-to-your-function-file'); // Import the function\n\ndescribe('isSumLessThan100', () =\u003e {\n test('should return true for numbers summing to less than 100', () =\u003e {\n const result = isSumLessThan100(5, 10);\n expect(result).toBe(true);\n });\n});\n```",
"sig": "ca334e95db0711dfca165dad4590ae45223b845da0476053de02f882ac405a4d9d70ce0e95b31a625946c7786b6ef79b8f71062f6fa5c0c1d8cb3a9881c9b54b"
}