Skip to content

Commit

Permalink
triangle: update to latest (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored Jan 13, 2025
1 parent e070e10 commit eee3090
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 74 deletions.
18 changes: 18 additions & 0 deletions exercises/practice/triangle/.meta/generator.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns triangle-test
(:require [clojure.test :refer [deftest testing is]]
triangle))
{{#test_cases.equilateral}}
(deftest equilateral?_test_{{idx}}
(testing "{{description}}"
(is ({{#expected}}true?{{else}}false?{{/expected}} (triangle/equilateral? {{input.sides.0}} {{input.sides.1}} {{input.sides.2}})))))
{{/test_cases.equilateral~}}
{{#test_cases.isosceles}}
(deftest isosceles?_test_{{idx}}
(testing "{{description}}"
(is ({{#expected}}true?{{else}}false?{{/expected}} (triangle/isosceles? {{input.sides.0}} {{input.sides.1}} {{input.sides.2}})))))
{{/test_cases.isosceles~}}
{{#test_cases.scalene}}
(deftest scalene?_test_{{idx}}
(testing "{{description}}"
(is ({{#expected}}true?{{else}}false?{{/expected}} (triangle/scalene? {{input.sides.0}} {{input.sides.1}} {{input.sides.2}})))))
{{/test_cases.scalene~}}
57 changes: 35 additions & 22 deletions exercises/practice/triangle/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,60 +1,73 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[8b2c43ac-7257-43f9-b552-7631a91988af]
description = "all sides are equal"
description = "equilateral triangle -> all sides are equal"

[33eb6f87-0498-4ccf-9573-7f8c3ce92b7b]
description = "any side is unequal"
description = "equilateral triangle -> any side is unequal"

[c6585b7d-a8c0-4ad8-8a34-e21d36f7ad87]
description = "no sides are equal"
description = "equilateral triangle -> no sides are equal"

[16e8ceb0-eadb-46d1-b892-c50327479251]
description = "all zero sides is not a triangle"
description = "equilateral triangle -> all zero sides is not a triangle"

[3022f537-b8e5-4cc1-8f12-fd775827a00c]
description = "sides may be floats"
description = "equilateral triangle -> sides may be floats"

[cbc612dc-d75a-4c1c-87fc-e2d5edd70b71]
description = "last two sides are equal"
description = "isosceles triangle -> last two sides are equal"

[e388ce93-f25e-4daf-b977-4b7ede992217]
description = "first two sides are equal"
description = "isosceles triangle -> first two sides are equal"

[d2080b79-4523-4c3f-9d42-2da6e81ab30f]
description = "first and last sides are equal"
description = "isosceles triangle -> first and last sides are equal"

[8d71e185-2bd7-4841-b7e1-71689a5491d8]
description = "equilateral triangles are also isosceles"
description = "isosceles triangle -> equilateral triangles are also isosceles"

[840ed5f8-366f-43c5-ac69-8f05e6f10bbb]
description = "no sides are equal"
description = "isosceles triangle -> no sides are equal"

[2eba0cfb-6c65-4c40-8146-30b608905eae]
description = "first triangle inequality violation"
description = "isosceles triangle -> first triangle inequality violation"

[278469cb-ac6b-41f0-81d4-66d9b828f8ac]
description = "second triangle inequality violation"
description = "isosceles triangle -> second triangle inequality violation"

[90efb0c7-72bb-4514-b320-3a3892e278ff]
description = "third triangle inequality violation"
description = "isosceles triangle -> third triangle inequality violation"

[adb4ee20-532f-43dc-8d31-e9271b7ef2bc]
description = "sides may be floats"
description = "isosceles triangle -> sides may be floats"

[e8b5f09c-ec2e-47c1-abec-f35095733afb]
description = "no sides are equal"
description = "scalene triangle -> no sides are equal"

[2510001f-b44d-4d18-9872-2303e7977dc1]
description = "all sides are equal"
description = "scalene triangle -> all sides are equal"

[c6e15a92-90d9-4fb3-90a2-eef64f8d3e1e]
description = "two sides are equal"
description = "scalene triangle -> first and second sides are equal"

[3da23a91-a166-419a-9abf-baf4868fd985]
description = "scalene triangle -> first and third sides are equal"

[b6a75d98-1fef-4c42-8e9a-9db854ba0a4d]
description = "scalene triangle -> second and third sides are equal"

[70ad5154-0033-48b7-af2c-b8d739cd9fdc]
description = "may not violate triangle inequality"
description = "scalene triangle -> may not violate triangle inequality"

[26d9d59d-f8f1-40d3-ad58-ae4d54123d7d]
description = "sides may be floats"
description = "scalene triangle -> sides may be floats"
28 changes: 15 additions & 13 deletions exercises/practice/triangle/src/triangle.clj
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
(ns triangle)

(defn is-valid? [] ;; <- arglist goes here
;; your code goes here
)
(defn equilateral?
"Returns true if the triangle with sides a, b, and c is equilateral; otherwise, returns false"
[a b c]
;; function body
)

(defn equilateral? [] ;; <- arglist goes here
;; your code goes here
)
(defn isosceles?
"Returns true if the triangle with sides a, b, and c is isosceles; otherwise, returns false"
[a b c]
;; function body
)

(defn isosceles? [] ;; <- arglist goes here
;; your code goes here
)

(defn scalene? [] ;; <- arglist goes here
;; your code goes here
)
(defn scalene?
"Returns true if the triangle with sides a, b, and c is scalene; otherwise, returns false"
[a b c]
;; function body
)
105 changes: 66 additions & 39 deletions exercises/practice/triangle/test/triangle_test.clj
Original file line number Diff line number Diff line change
@@ -1,60 +1,87 @@
(ns triangle-test
(:require [clojure.test :refer [deftest is testing]]
(:require [clojure.test :refer [deftest testing is]]
triangle))

(deftest equilateral-all-sides-equal
(is (true? (triangle/equilateral? 2 2 2))))
(deftest equilateral?_test_1
(testing "equilateral triangle - all sides are equal"
(is (true? (triangle/equilateral? 2 2 2)))))

(deftest equilateral-any-side-is-unequal
(is (false? (triangle/equilateral? 2 3 2))))
(deftest equilateral?_test_2
(testing "equilateral triangle - any side is unequal"
(is (false? (triangle/equilateral? 2 3 2)))))

(deftest equilateral-no-sides-are-equal
(is (false? (triangle/equilateral? 5 4 6))))
(deftest equilateral?_test_3
(testing "equilateral triangle - no sides are equal"
(is (false? (triangle/equilateral? 5 4 6)))))

(deftest equilateral-all-zero-sides
(is (false? (triangle/equilateral? 0 0 0))))
(deftest equilateral?_test_4
(testing "equilateral triangle - all zero sides is not a triangle"
(is (false? (triangle/equilateral? 0 0 0)))))

(deftest equilateral-sides-may-be-floats
(is (true? (triangle/equilateral? 0.5 0.5 0.5))))
(deftest equilateral?_test_5
(testing "equilateral triangle - sides may be floats"
(is (true? (triangle/equilateral? 0.5 0.5 0.5)))))

(deftest isosceles-last-two-sides-equal
(is (true? (triangle/isosceles? 3 4 4))))
(deftest isosceles?_test_1
(testing "isosceles triangle - last two sides are equal"
(is (true? (triangle/isosceles? 3 4 4)))))

(deftest isosceles-first-two-sides-equal
(is (true? (triangle/isosceles? 4 4 3))))
(deftest isosceles?_test_2
(testing "isosceles triangle - first two sides are equal"
(is (true? (triangle/isosceles? 4 4 3)))))

(deftest isosceles-first-last-sides-equal
(is (true? (triangle/isosceles? 4 3 4))))
(deftest isosceles?_test_3
(testing "isosceles triangle - first and last sides are equal"
(is (true? (triangle/isosceles? 4 3 4)))))

(deftest isosceles-equilateral-triangles-also-isosceles
(is (true? (triangle/isosceles? 4 4 4))))
(deftest isosceles?_test_4
(testing "isosceles triangle - equilateral triangles are also isosceles"
(is (true? (triangle/isosceles? 4 4 4)))))

(deftest isosceles-no-sides-equal
(is (false? (triangle/isosceles? 2 3 4))))
(deftest isosceles?_test_5
(testing "isosceles triangle - no sides are equal"
(is (false? (triangle/isosceles? 2 3 4)))))

(deftest isosceles-first-triangle-inequality-violation
(is (false? (triangle/isosceles? 1 1 3))))
(deftest isosceles?_test_6
(testing "isosceles triangle - first triangle inequality violation"
(is (false? (triangle/isosceles? 1 1 3)))))

(deftest isosceles-second-triangle-inequality-violation
(is (false? (triangle/isosceles? 1 3 1))))
(deftest isosceles?_test_7
(testing "isosceles triangle - second triangle inequality violation"
(is (false? (triangle/isosceles? 1 3 1)))))

(deftest isosceles-third-triangle-inequality-violation
(is (false? (triangle/isosceles? 3 1 1))))
(deftest isosceles?_test_8
(testing "isosceles triangle - third triangle inequality violation"
(is (false? (triangle/isosceles? 3 1 1)))))

(deftest isosceles-sides-may-be-floats
(is (true? (triangle/isosceles? 0.5 0.4 0.5))))
(deftest isosceles?_test_9
(testing "isosceles triangle - sides may be floats"
(is (true? (triangle/isosceles? 0.5 0.4 0.5)))))

(deftest scalene-no-sides-are-equal
(is (true? (triangle/scalene? 5 4 6))))
(deftest scalene?_test_1
(testing "scalene triangle - no sides are equal"
(is (true? (triangle/scalene? 5 4 6)))))

(deftest scalene-all-sides-equal
(is (false? (triangle/scalene? 4 4 4))))
(deftest scalene?_test_2
(testing "scalene triangle - all sides are equal"
(is (false? (triangle/scalene? 4 4 4)))))

(deftest scalene-two-sides-equal
(is (false? (triangle/scalene? 4 4 3))))
(deftest scalene?_test_3
(testing "scalene triangle - first and second sides are equal"
(is (false? (triangle/scalene? 4 4 3)))))

(deftest scalene-may-not-violate-triangle-inequality
(is (false? (triangle/scalene? 7 3 2))))
(deftest scalene?_test_4
(testing "scalene triangle - first and third sides are equal"
(is (false? (triangle/scalene? 3 4 3)))))

(deftest scalene-sides-may-be-floats
(is (true? (triangle/scalene? 0.5 0.4 0.6))))
(deftest scalene?_test_5
(testing "scalene triangle - second and third sides are equal"
(is (false? (triangle/scalene? 4 3 3)))))

(deftest scalene?_test_6
(testing "scalene triangle - may not violate triangle inequality"
(is (false? (triangle/scalene? 7 3 2)))))

(deftest scalene?_test_7
(testing "scalene triangle - sides may be floats"
(is (true? (triangle/scalene? 0.5 0.4 0.6)))))

0 comments on commit eee3090

Please sign in to comment.