That's what fixtures are for: https://clojuredocs.org/clojure.test/use-fixtures
(with-fixture :each (reset-games)) As a side notes, in Lisp it is convention to append "!" to those functions that have side-effects (i.e. mutate state). A good candidate would be `reset-games!`. On Monday, April 13, 2015 at 9:18:21 PM UTC+2, Andrea Crotti wrote: > > Awesome thanks, the only thing is that the reason why I did the > reset-games thing is because in the tests I can reset things every > time. > > (testing "create new game" > (reset-games) > (new-game) > (is (= 1 (length-current-games)))) > > If I don't do that then it's harder in the tests to have a clean > environment.. > Maybe that shows a wrong approach in general. > These are the tests I'm talking about > > https://github.com/AndreaCrotti/hackthetower_clojurescript/blob/master/hangman/test/hangman/secret_test.clj > > > 2015-04-11 10:02 GMT+01:00 Sebastian Bensusan <sbe...@gmail.com > <javascript:>>: > > Hi, > > > > I browsed over it, a couple of things: > > > > `defonce` is meant for code reloading: > > > > (defonce live-games (ref {}))) > > > > Don't use `for` when you can use `map`: > > > > (mapv (fn [i] {:char i :visible (not (valid-char i))})) > > > > Strings can be treated as sequences: > > > > (first (.toLowerCase (str char))) > > > > Hope this helps > > > > Sebastian > > > > On Friday, April 10, 2015 at 11:35:33 AM UTC+2, Andrea Crotti wrote: > >> > >> I created a small project just for learning more Clojure and wanted > some > >> feedback to improve it and learn some more. > >> > >> The code is all here, and it's both a desktop app that can be run with > >> "lein run" or a web API that can be run with "lein ring server": > >> > >> > >> > https://github.com/AndreaCrotti/hackthetower_clojurescript/tree/master/hangman > > >> > >> The game is basically this > >> http://en.wikipedia.org/wiki/Hangman_%28game%29 (without the fancy > >> graphics still) > >> > >> This is the sample structure of a move right now: > >> {:attempts 0 > >> :seen #{} > >> :struct [{:char \a :visible false} {:char \b :visible false} {:char > >> \c :visible false}]} > >> > >> So every time someone makes a move it will add a new game position to > >> a list of game snapshots, for example: > >> > >> {"long-game-id": [{:attempts 1 :seen ${\a} :struct [{...}]} {:attempts > >> 0 :seen #{} :struct [{...}]}]} > >> > >> and so on and so forth. > >> > >> This is the function that alters the reference for example > >> > >> (defn set-secret > >> "Set the secret for a given name" > >> [game-id game-struct] > >> (dosync > >> (alter live-games > >> (fn [d] (assoc d game-id (conj (get d game-id) > game-struct)))))) > >> > >> Any suggestions is welcome, I also had some troubles trying to > >> minimize the refs/atoms while at the same time avoiding passing too > >> many things around. > >> > >> I think now the solution of using game-id to hide the implementation > >> detail in > >> > https://github.com/AndreaCrotti/hackthetower_clojurescript/blob/master/hangman/src/hangman/secret.clj > > >> is not too bad but open for better ideas. > >> > >> Thanks a lot, and if anyone is interested in joining the project > >> please let me know. > >> > >> PS. next things to do are some deployment nice stuff, graphics with > >> Quill and a UI with Clojurescript > > > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clo...@googlegroups.com > <javascript:> > > Note that posts from new members are moderated - please be patient with > your > > first post. > > To unsubscribe from this group, send email to > > clojure+u...@googlegroups.com <javascript:> > > For more options, visit this group at > > http://groups.google.com/group/clojure?hl=en > > --- > > You received this message because you are subscribed to the Google > Groups > > "Clojure" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to clojure+u...@googlegroups.com <javascript:>. > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.