# Something between =, == and identical?

**URL:** https://clojureverse.org/t/something-between-and-identical/9786
**Category:** General Questions
**Created:** [February 14, 2023, 2:24pm UTC](https://clojureverse.org/t/something-between-and-identical/9786 "2023-02-14T14:24:14Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![foobar](https://clojureverse.org/letter_avatar_proxy/v4/letter/f/f19dbf/32.png) [@foobar](https://clojureverse.org/u/foobar)
#### Post date: [February 14, 2023, 2:24pm UTC](https://clojureverse.org/t/something-between-and-identical/9786/1 "2023-02-14T14:24:14Z")

</div>

Hi folks,

I’m after something like `=`, `==` and `identical?` but neither of those work like I want to.

I would like to write tests that report difference between `[1 2 3]` and `'(1 2 3)`. Is that possible without using `vector?`?

This doesn’t what I need:

```auto
(identical? '(1) '(1))
false

```

And same for:

```auto
(== '(1) '(1))
exception

```

So I’m using `=` but sometime it is annoying. For example when output is `'([1 2] [3 4])`. If something happens and output turns into `'((1 2) (3 4))` I would like to know that without testing `(first (vector? ...`.

Thank you.

---

<div class="post-metadata">

### Author: ![John\_Newman](https://clojureverse.org/user_avatar/clojureverse.org/john_newman/32/1254_2.png) [@John\_Newman](https://clojureverse.org/u/John_Newman)
#### Post date: [February 14, 2023, 4:08pm UTC](https://clojureverse.org/t/something-between-and-identical/9786/2 "2023-02-14T16:08:07Z")

</div>

Can you give an example of what test you want to use?

Maybe something like:

```clojure
(defn same? [& body]
  (and (apply = body)
       (->> body (map type) (apply =))))

#_=> (same? '(1) [1])
false

```

---

<div class="post-metadata">

### Author: ![Serioga](https://clojureverse.org/user_avatar/clojureverse.org/serioga/32/5290_2.png) [@Serioga](https://clojureverse.org/u/Serioga)
#### Post date: [February 14, 2023, 9:03pm UTC](https://clojureverse.org/t/something-between-and-identical/9786/3 "2023-02-14T21:03:01Z")

</div>

Hello @foobar.

Do you want following to be equal or not?

```clojure
    (list (list 1 2) (list 3 4))
    (list (map identity [1 2]) (map identity [3 4]))

```

both printed as `((1 2) (3 4))` but elements has different type.

---

<div class="post-metadata">

### Author: ![dave.liepmann](https://clojureverse.org/user_avatar/clojureverse.org/dave.liepmann/32/5211_2.png) [@dave.liepmann](https://clojureverse.org/u/dave.liepmann)
#### Post date: [February 14, 2023, 9:23pm UTC](https://clojureverse.org/t/something-between-and-identical/9786/4 "2023-02-14T21:23:38Z")

</div>

Welcome 🙂

Very similar, very recent thread might be of interest: [Equality is a Problem](https://v2.clojureverse.org/t/equality-is-a-problem/9780)

Regarding why `identical?` and `==` aren’t what you want, and this topic in general, [Clojure - Equality](https://clojure.org/guides/equality) is good reading if you haven’t yet seen it.

---

<div class="post-metadata">

### Author: ![foobar](https://clojureverse.org/letter_avatar_proxy/v4/letter/f/f19dbf/32.png) [@foobar](https://clojureverse.org/u/foobar)
#### Post date: [February 15, 2023, 12:07pm UTC](https://clojureverse.org/t/something-between-and-identical/9786/5 "2023-02-15T12:07:38Z")

</div>

> [@John\_Newman](#):
>
> what test you want to use

Thank you John.

I want to use it in `clojure.test` only since I understand that I should rather have code that can work with any collection rather than relying on vector / list.

> [@Serioga](#):
>
> printed as `((1 2) (3 4))` but elements has different type

Good point, thank you Serioga. For testing I’d like to have fn that distinguish between vector, set and everything else (list or what it returned from `seq` / `map`). I had a thought about something like `(= (str ...) (str ...))` but that would be just sooo wrong ;-).

> [@dave.liepmann](#):
>
> might be of interest: [Equality is a Problem](https://v2.clojureverse.org/t/equality-is-a-problem/9780)

Thank you Dave. I googled that one and read it. I don’t remember the blog post from the second link but I spent enough time in Clojure (I’m NOT expert but I think I know core principles) to understand that I should not rely on data types. I should rely just on shape of my data. But I was hoping that specifically for `clojure.test` testing there will be something more than those three functions I know.

---

<div class="post-metadata">

### Author: ![Serioga](https://clojureverse.org/user_avatar/clojureverse.org/serioga/32/5290_2.png) [@Serioga](https://clojureverse.org/u/Serioga)
#### Post date: [February 15, 2023, 2:14pm UTC](https://clojureverse.org/t/something-between-and-identical/9786/6 "2023-02-15T14:14:03Z")

</div>

Martin, I suggest to be specific in your tests. You can validate data shape and contents separately like

```clojure
;; Spec can be used as well to test data shape

(defn valid-elem? [x]
  (and (vector? x)
       (= 2 (count x))))

(defn valid-seq? [xs]
  (and (seq xs)
       (every? valid-elem? xs)))

(let [xs '([1 2] [3 4])]
  (and (valid-seq? xs)
       (= '([1 2] [3 4]) xs)))
#_=> true

(let [xs '('(1 2) '(3 4))]
  (and (valid-seq? xs)
       (= '([1 2] [3 4]) xs)))
#_=> false

```

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [August 17, 2023, 2:14am UTC](https://clojureverse.org/t/something-between-and-identical/9786/7 "2023-08-17T02:14:16Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
