Skip to content

marcinwaldowski/cljc-4clojure-solutions

Repository files navigation

cljc-4clojure-solutions

This project shows how much effort was required to port 4Clojure solutions written in Clojure to ClojureScript (see commit log). It also documents some approaches to execute unit test for various ClojureScript host environments.

Warning! Please do not use this project as a source of hints for solving 4clojure problems. It's best to first solve the problem and only after that looking at others solutions.

All unit tests are in file test/cljc_4clojure_solutions/core_test.cljc. All non trivial solutions can be found in file src/cljc_4clojure_solutions/core.cljc. All other files are just "infrastructure".

Prerequisites

  • Install Java 8.
  • Install Leiningen.

Clojure

Compile

Execute lein compile :all. JVM bytecode .class files can be found in target directory.

Run tests

  • By Leiningen command.

    Execute lein test.

  • From REPL.

    Execute lein repl. Then from the REPL execute:

    (require '[clojure.test :as t])
    (require 'cljc-4clojure-solutions.core-test)
    (t/run-tests 'cljc-4clojure-solutions.core-test)

    In REPL it's easy to test functions directly:

    (require '[cljc-4clojure-solutions.core :as core])
    (core/num->roman 578)
    (core/prime 40)

Clojurescript

Compile

Compile by executing one of commands below. The result is testable.js file under /resources/private/js directory.

lein cljsbuild once none        # no optimization
lein cljsbuild once whitespace  # whitespace optimization
lein cljsbuild once simple      # simple optimization
lein cljsbuild once advanced    # advanced optimization
lein cljsbuild once node        # compilation for Node.js
lein cljsbuild once brepl       # compilation for browser REPL

Running tests with PhantomJS

Make sure PhantomJS is correctly installed:

$ phantomjs -v
2.1.3-dev-release

Execute command:

lein doo phantom whitespace once

The whitespace can be exchanged with simple or advanced.

Running tests with Node.js

Make sure Node.js is correctly installed:

$ node -v
v8.9.4

Execute command:

lein doo node node once

Running tests with Nashorn

Execute command:

lein doo nashorn whitespace once

The whitespace can be exchanged with simple or advanced.

Running tests with Rhino

Make sure Rhino is correctly installed:

rhino -help

Execute command:

lein doo rhino whitespace once

The whitespace can be exchanged with simple or advanced.

Running tests from browser REPL

Compile sources to JavaScript:

lein cljsbuild once brepl

Open REPL:

lein repl

In REPL start Weasel server:

(start-weasel)

It will wait for connection from browser. Open resources/private/brepl.html in modern browser. This causes browser to connect to Weasel and changes REPL prompt to cljs.user=>.

Run tests by executing:

(require '[cljs.test :as t])
(require 'cljc-4clojure-solutions.core-test)
(t/run-tests 'cljc-4clojure-solutions.core-test)

In REPL it's easy to test functions directly:

(require '[cljc-4clojure-solutions.core :as core])
(core/num->roman 578)
(core/prime 40)

Running tests from Node.js REPL

Open REPL:

lein repl

In REPL switch to Node.js REPL:

(start-node)

Run tests by executing:

(require '[cljs.test :as t])
(require 'cljc-4clojure-solutions.core-test)
(t/run-tests 'cljc-4clojure-solutions.core-test)

In REPL it's easy to test functions directly:

(require '[cljc-4clojure-solutions.core :as core])
(core/num->roman 578)
(core/prime 40)

Running tests from Nashorn REPL

Proceed the same way as with Node.js REPL but run (start-nashorn) instead of (start-node).

Running tests from Rhino REPL

Proceed the same way as with Node.js REPL but run (start-rhino) instead of (start-node).

Running tests with Planck

Make sure Planck is correctly installed:

$ planck -h

Run planck with:

planck -c src:test

In planck execute:

(require '[clojure.test :as t])
(require 'cljc-4clojure-solutions.core-test)
(t/run-tests 'cljc-4clojure-solutions.core-test)

License

Copyright © 2018 Marcin Waldowski

Distributed under the Eclipse Public License version 1.0

About

4Clojure solutions - Clojure/ClojureScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published