Giter Site home page Giter Site logo

cljc-4clojure-solutions's Introduction

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

cljc-4clojure-solutions's People

Contributors

marcinwaldowski avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.