Created
May 25, 2015 17:14
-
-
Save fcanas/a7762961aa8ca81c40ee to your computer and use it in GitHub Desktop.
Squared Same
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns squared-same-test | |
| (:require [clojure.test :refer :all] [clojure.set :refer :all]) ) | |
| (defn function_maps_sets [f, a, b] | |
| (= 0 (count (difference (set b) (set (map f a))))) | |
| ) | |
| (defn function_is_map_between_sets [f, a, b] | |
| (def setA (set a)) | |
| (def setB (set b)) | |
| (or (function_maps_sets f setA setB) (function_maps_sets f setA setB)) | |
| ) | |
| (defn squared_same [a, b] | |
| (if (= nil a) false | |
| (if (= nil b) false | |
| (function_maps_a_to_b (fn [a] (* a a)) a b) | |
| ) | |
| ) | |
| ) | |
| (deftest basic-test | |
| (testing "Test 1" | |
| (def a [121, 144, 19, 161, 144, 19, 11]) | |
| (def b [121, 14641, 20736, 361, 25921, 361, 20736, 361]) | |
| (is (= (squared_same a b) true))) | |
| (testing "Test 2" | |
| (def a [121, 144, 19, 161, 144, 19, 11]) | |
| (def b [121, 14641, 20736, 361000, 25921, 361, 20736, 361]) | |
| (is (= (squared_same a b) false))) | |
| (testing "Test 3" | |
| (def a []) | |
| (def b [1]) | |
| (is (= (squared_same a b) false))) | |
| (testing "Test 4" | |
| (def a []) | |
| (def b nil) | |
| (is (= (squared_same a b) false))) | |
| (testing "Test 5" | |
| (def a []) | |
| (def b []) | |
| (is (= (squared_same a b) true))) | |
| (testing "Test 6" | |
| (def a [121, 144, 19, 161, 144, 19, 11, 1008]) | |
| (def b [(* 11 11), (* 121 121), (* 144 144), (* 190 190), (* 161 161), (* 19 19), (* 144 144), (* 19 19)]) | |
| (is (= (squared_same a b) false))) | |
| (testing "Test 7" | |
| (def a [121, 1440, 191, 161, 144, 19, 11, 195]) | |
| (def b [(* 11 11), (* 121 121), (* 1440 1440), (* 191 191), (* 161 161), (* 19 19), (* 144 144), (* 195 195)]) | |
| (is (= (squared_same a b) true))) | |
| (testing "Test 8" | |
| (def a [0, 12, 191, 161, 19, 144, 195, 1]) | |
| (def b [0, (* 12 12), (* 144 144), (* 191 191), (* 161 161), (* 19 19), (* 195 195) 1]) | |
| (is (= (squared_same a b) true))) | |
| ) | |
| (run-tests) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment