Skip to content

Instantly share code, notes, and snippets.

@createthis
Created March 31, 2025 13:16
Show Gist options
  • Save createthis/4fb3b02262b52d5115c8212914e45521 to your computer and use it in GitHub Desktop.
Save createthis/4fb3b02262b52d5115c8212914e45521 to your computer and use it in GitHub Desktop.
larry vibe coding demo - prompt 1
We have some code:
**bjj_calculate_match_difficulty.js**
```js
function calculateMatchDifficulty(practitioner1, practitioner2) {
const beltRanks = ['white', 'blue', 'purple', 'brown', 'black'];
// Calculate the difference in belt ranks
const beltDiff = beltRanks.indexOf(practitioner2.belt) - beltRanks.indexOf(practitioner1.belt);
// Calculate the cumulative effect of age, weight, and height
let ageDiff = (practitioner1.age - practitioner2.age) / 10;
let weightDiff = (practitioner2.weightInPounds - practitioner1.weightInPounds) / 20;
let heightDiff = (practitioner2.heightInInches - practitioner1.heightInInches) / 6;
let cumulativeEffect = ageDiff + weightDiff + heightDiff;
console.log(`ageDiff=${ageDiff}`);
console.log(`weightDiff=${weightDiff}`);
console.log(`heightDiff=${heightDiff}`);
console.log(`beltDiff=${beltDiff}`);
// Return the cumulative effect as a floating-point number
return (beltDiff + cumulativeEffect) * -1;
}
```
And we have some unit tests written in swift:
```swift
//
// BjjTests.swift
//
//
//
import XCTest
@testable import bjjCalculateMatchDifficulty
final class BjjTests: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testParsePractitioner() throws {
let json = """
{
"belt": "white",
"age": 42,
"weightInPounds": 175,
"heightInInches": 69
}
"""
let practitioner = try Bjj.parsePractitioner(json: json)
XCTAssertEqual(practitioner.belt, "white")
XCTAssertEqual(practitioner.age, 42)
XCTAssertEqual(practitioner.weightInPounds, 175)
XCTAssertEqual(practitioner.heightInInches, 69)
}
func testCalculateMatchDifficulty() throws {
let practitioner1 = Bjj.Practitioner(belt: "white", age: 42, weightInPounds: 175, heightInInches: 69)
let practitioner2 = Bjj.Practitioner(belt: "blue", age: 32, weightInPounds: 195, heightInInches: 75)
let result = try Bjj.calculateMatchDifficulty(practitioner1: practitioner1, practitioner2: practitioner2)
XCTAssertEqual(result, -4.0)
}
func testCalculateMatchDifficulty2() throws {
let practitioner1 = Bjj.Practitioner(belt: "white", age: 42, weightInPounds: 175, heightInInches: 69)
let practitioner2 = Bjj.Practitioner(belt: "blue", age: 25, weightInPounds: 160, heightInInches: 65)
let result = try Bjj.calculateMatchDifficulty(practitioner1: practitioner1, practitioner2: practitioner2)
XCTAssertEqual(result, -1.2833333)
}
}
```
Please transcode the tests to javascript so that our javascript code has unit tests. Use jest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment