├── .gitmodules
├── .jshintrc
├── examples
├── samplecode.txt
├── sounds
│ ├── glass.mp3
│ ├── glass.ogg
│ ├── beer_can_opening.mp3
│ ├── beer_can_opening.ogg
│ └── sounds.html
├── manual-graph.html
├── slideshow.html
├── binarytree.html
├── findmax.html
├── sudoku.html
├── keyvaluepair.html
├── list.html
├── pseudocode.html
├── graph.html
├── simple-exercise.html
├── allStructures.html
└── pointers.html
├── css
└── images
│ ├── spinner.gif
│ ├── settings.png
│ ├── sound-off.png
│ └── sound-icon.png
├── src
├── front1.txt
├── version2.txt
├── front2.txt
├── version1.txt
├── events.js
├── translations.js
├── core.js
├── messages.js
├── matrix.js
├── settings.js
├── keyvaluepair.js
├── questions.js
├── effects.js
└── anim.js
├── .travis.yml
├── extras
├── stack.css
├── sound.js
├── lib
│ └── ion.sound.js
└── stack.js
├── .gitignore
├── test
├── utils
│ ├── arrayutils.js
│ ├── qunit-assert-close.js
│ └── qunit.css
├── unit
│ ├── core.js
│ ├── keyvaluepair.js
│ ├── exercise.js
│ ├── utils.js
│ ├── anim.js
│ ├── graph.js
│ └── list.js
└── index.html
├── MIT-license.txt
├── package.json
├── Makefile
├── README.md
├── Gruntfile.js
└── Changelog.txt
/.gitmodules:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vkaravir/JSAV/HEAD/.jshintrc
--------------------------------------------------------------------------------
/examples/samplecode.txt:
--------------------------------------------------------------------------------
1 | line1 from a URL
2 | line2
3 | line 3
--------------------------------------------------------------------------------
/css/images/spinner.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vkaravir/JSAV/HEAD/css/images/spinner.gif
--------------------------------------------------------------------------------
/src/front1.txt:
--------------------------------------------------------------------------------
1 | /*!
2 | * JSAV - JavaScript Algorithm Visualization Library
3 | * Version
--------------------------------------------------------------------------------
/css/images/settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vkaravir/JSAV/HEAD/css/images/settings.png
--------------------------------------------------------------------------------
/css/images/sound-off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vkaravir/JSAV/HEAD/css/images/sound-off.png
--------------------------------------------------------------------------------
/css/images/sound-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vkaravir/JSAV/HEAD/css/images/sound-icon.png
--------------------------------------------------------------------------------
/examples/sounds/glass.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vkaravir/JSAV/HEAD/examples/sounds/glass.mp3
--------------------------------------------------------------------------------
/examples/sounds/glass.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vkaravir/JSAV/HEAD/examples/sounds/glass.ogg
--------------------------------------------------------------------------------
/src/version2.txt:
--------------------------------------------------------------------------------
1 | ";
2 |
3 | JSAV.version = function() {
4 | return theVERSION;
5 | };
6 | })();
7 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "6"
4 | before_script:
5 | - npm install -g grunt-cli
6 |
--------------------------------------------------------------------------------
/examples/sounds/beer_can_opening.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vkaravir/JSAV/HEAD/examples/sounds/beer_can_opening.mp3
--------------------------------------------------------------------------------
/examples/sounds/beer_can_opening.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vkaravir/JSAV/HEAD/examples/sounds/beer_can_opening.ogg
--------------------------------------------------------------------------------
/src/front2.txt:
--------------------------------------------------------------------------------
1 |
2 | * Copyright (c) 2011-2015 by Ville Karavirta and Cliff Shaffer
3 | * Released under the MIT license.
4 | */
5 |
--------------------------------------------------------------------------------
/src/version1.txt:
--------------------------------------------------------------------------------
1 | /**
2 | * Version support
3 | * Depends on core.js
4 | */
5 | (function() {
6 | if (typeof JSAV === "undefined") { return; }
7 | var theVERSION = "
--------------------------------------------------------------------------------
/extras/stack.css:
--------------------------------------------------------------------------------
1 | .jsavstack {
2 | position: relative;
3 | background-color: inherit;
4 | }
5 | .jsavstacknode {
6 | position: absolute;
7 | border-radius: 5px;
8 | width: 45px;
9 | height: 45px;
10 | z-index: 100;
11 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #Temp files
2 | *~
3 | #Mac stuff
4 | .DS_Store
5 |
6 | #build directory
7 | build
8 |
9 | #Eclipse settings
10 | .project
11 | .settings
12 |
13 | #InteliJ IDE settings
14 | .idea
15 |
16 | #Generated files
17 | src/version.txt
18 | src/front.js
19 | src/version.js
20 | node_modules
21 |
--------------------------------------------------------------------------------
/extras/sound.js:
--------------------------------------------------------------------------------
1 | (function($) {
2 | "use strict";
3 | JSAV.ext.sound = JSAV.anim(function(filename, options) {
4 | $.ionSound.addSound(filename);
5 |
6 | if (this._soundPlaying) { // stop previous sound
7 | // this._soundPlaying is never cleared; we can still stop it
8 | $.ionSound.stop(this._soundPlaying);
9 | }
10 |
11 | // start the new sound
12 | if (this._shouldAnimate()) {
13 | this._soundPlaying = filename;
14 | $.ionSound.play(filename);
15 | }
16 | return [filename, options];
17 | });
18 |
19 | // register function to be called when JSAV is initialized
20 | JSAV.init(function(options) {
21 | // initialize ionSound on JSAV initialization
22 | $.ionSound({sounds: [], path: options.soundPath || "./" });
23 | });
24 | }(jQuery));
--------------------------------------------------------------------------------
/test/utils/arrayutils.js:
--------------------------------------------------------------------------------
1 | var arrayUtils = {
2 |
3 | testArrayHighlights: function(arr, hlIndices) {
4 | for (var i = 0, l = arr.size(); i < l; i++) {
5 | // test highlights through array.isHighlight
6 | equal(arr.isHighlight(i), hlIndices[i]);
7 | // test highlights through the corresponding index objects
8 | equal(arr.index(i).isHighlight(), hlIndices[i]);
9 | }
10 | },
11 |
12 | testArrayValues: function(arr, values) {
13 | equal(arr.size(), values.length, "Equal array sizes");
14 | for (var i = 0, l = values.length; i < l; i++) {
15 | // test values through array
16 | equal(arr.value(i), values[i], "Values in index " + i);
17 | // test values through the corresponding index objects
18 | equal(arr.index(i).value(), values[i]);
19 | }
20 | }
21 | };
22 |
--------------------------------------------------------------------------------
/MIT-license.txt:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Copyright (c) 2011- Ville Karavirta and Cliff Shaffer
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "JSAV",
3 | "version": "1.0.1",
4 | "description": "JSAV - The JavaScript Algorithm Visualization Library",
5 | "homepage": "http://jsav.io/",
6 | "license": "MIT",
7 | "author": "Ville Karavirta ",
8 | "contributors": [
9 | {
10 | "name": "Cliff Shaffer"
11 | },
12 | {
13 | "name": "Ville Karavirta",
14 | "email": "ville@villekaravirta.com"
15 | },
16 | {
17 | "name": "Matthew Micallef",
18 | "email": "mattmicallef@outlook.com"
19 | }
20 | ],
21 | "directories": {
22 | "example": "Example usages of JSAV",
23 | "test": "Unittests",
24 | "src": "The JS sourcefiles"
25 | },
26 | "repository": {
27 | "type": "git",
28 | "url": "https://github.com/vkaravir/JSAV.git"
29 | },
30 | "bugs": {
31 | "url": "https://github.com/vkaravir/JSAV/issues"
32 | },
33 | "scripts": {
34 | "test": "grunt test"
35 | },
36 | "devDependencies": {
37 | "grunt": "^1.0.1",
38 | "grunt-contrib-concat": "^1.0.1",
39 | "grunt-contrib-copy": "^1.0.0",
40 | "grunt-contrib-csslint": "^2.0.0",
41 | "grunt-contrib-jshint": "^1.1.0",
42 | "grunt-contrib-qunit": "^2.0.0",
43 | "grunt-contrib-uglify": "^3.2.1",
44 | "grunt-contrib-watch": "^1.0.0",
45 | "grunt-exec": "^3.0.0",
46 | "grunt-gitinfo": "^0.1.8",
47 | "load-grunt-tasks": "^3.5.2"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/examples/sounds/sounds.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Example of Sounds in JSAV
5 |
6 |
17 |
18 |
19 |
Example of All Data Structures in JSAV
20 |
Note: the sounds used are part of the Ion.Sound jQuery plugin and are licensed under the MIT license.
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/test/unit/core.js:
--------------------------------------------------------------------------------
1 | /*global ok,test,module,deepEqual,equal,expect,equals,notEqual */
2 | module("core", { });
3 |
4 | test("JSAV", function() {
5 | expect(4);
6 | ok( JSAV, "JSAV" );
7 | ok( JSAV.ext, "JSAV extensions");
8 | ok( JSAV.init, "JSAV init");
9 | var av = new JSAV("emptycontainer");
10 | ok( av, "JSAV initialized" );
11 | });
12 |
13 | test("JSAV container options", function() {
14 | var avDOM = new JSAV(document.getElementById("emptycontainer"));
15 | ok(avDOM, "Passing a DOM element");
16 |
17 | var avjQuery = new JSAV($("#emptycontainer"));
18 | ok(avjQuery, "Passing a jQuery object");
19 |
20 | var avStringId = new JSAV("emptycontainer");
21 | ok(avStringId, "Passing an element id");
22 |
23 | var avDOMOpt = new JSAV({element: document.getElementById("emptycontainer")});
24 | ok(avDOMOpt, "Passing a DOM element as an option");
25 |
26 | var avjQueryOpt = new JSAV({element: jQuery("#emptycontainer")});
27 | ok(avjQueryOpt, "Passing a jQuery object as an option");
28 |
29 | var avSelectorOpt = new JSAV({element: "#emptycontainer"});
30 | ok(avSelectorOpt, "Passing a selector as an option");
31 |
32 | window.JSAV_OPTIONS = {element: "#emptycontainer"};
33 | var avSelectorGlobalOpt = new JSAV();
34 | ok(avSelectorGlobalOpt, "Element as a selector in global JSAV_OPTION");
35 | delete window.JSAV_OPTIONS;
36 | });
37 |
38 | test("JSAV Options", function() {
39 | // simple test to see if global JSAV_OPTIONS works
40 | window.JSAV_OPTIONS = {cat: 0, dog: 1};
41 | var av = new JSAV("emptycontainer", {cat: 3, turtle: 42});
42 | equal(av.options.turtle, 42, "Basic option preserved");
43 | equal(av.options.dog, 1, "Global option");
44 | equal(av.options.cat, 3, "Global option also specified on initialization");
45 | // delete the global variable
46 | delete window.JSAV_OPTIONS;
47 | });
--------------------------------------------------------------------------------
/examples/manual-graph.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Depth-First Search
5 |
6 |
7 |
8 |
JSAV example for graph with manual layout
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | RM = rm -rf
2 | LIB = lib
3 | MINIMIZE = uglifyjs $(TARGET)/JSAV.js --comments '/^!|@preserve|@license|@cc_on/i' >$(TARGET)/JSAV-min.js
4 | CAT = cat
5 | SRC = src
6 | TARGET = build
7 |
8 | SOURCES = $(SRC)/front.js $(SRC)/core.js $(SRC)/translations.js $(SRC)/anim.js $(SRC)/utils.js $(SRC)/messages.js $(SRC)/effects.js $(SRC)/events.js $(SRC)/graphicals.js $(SRC)/datastructures.js $(SRC)/array.js $(SRC)/tree.js $(SRC)/list.js $(SRC)/graph.js $(SRC)/matrix.js $(SRC)/code.js $(SRC)/settings.js $(SRC)/questions.js $(SRC)/exercise.js $(SRC)/version.js
9 |
10 | # This only works right when this is a submodule
11 | FETCH = ../.git/modules/JSAV/FETCH_HEAD
12 |
13 | all: build
14 |
15 | clean:
16 | $(RM) *~
17 | $(RM) build/*
18 | $(RM) examples/*~
19 | $(RM) src/*~ src/version.txt src/front.js src/version.js
20 | $(RM) css/*~
21 |
22 | build: $(TARGET)/JSAV.js $(TARGET)/JSAV-min.js
23 |
24 | $(TARGET)/JSAV.js: $(SRC)/version.txt $(SRC)/front.js $(SRC)/version.js $(SOURCES)
25 | -mkdir $(TARGET)
26 | $(CAT) $(SOURCES) > $(TARGET)/JSAV.js
27 |
28 | $(FETCH):
29 |
30 | $(SRC)/version.txt: $(FETCH)
31 | git describe --tags --long | awk '{ printf "%s", $$0 }' - > $(SRC)/version.txt
32 |
33 | $(SRC)/front.js: $(SRC)/front1.txt $(SRC)/version.txt $(SRC)/front2.txt
34 | $(CAT) $(SRC)/front1.txt $(SRC)/version.txt $(SRC)/front2.txt > $(SRC)/front.js
35 |
36 | $(SRC)/version.js :$(SRC)/version1.txt $(SRC)/version.txt $(SRC)/version2.txt
37 | $(CAT) $(SRC)/version1.txt $(SRC)/version.txt $(SRC)/version2.txt > $(SRC)/version.js
38 |
39 | $(TARGET)/JSAV-min.js: $(SRC)/version.txt $(SRC)/front.js $(SRC)/version.js $(SOURCES)
40 | -$(MINIMIZE)
41 |
42 | jshint:
43 | -jshint src/
44 |
45 | csslint:
46 | csslint --errors=empty-rules,import,errors --warnings=duplicate-background-images,compatible-vendor-prefixes,display-property-grouping,fallback-colors,duplicate-properties,shorthand,gradients,font-sizes,floats,overqualified-elements,import,regex-selectors,rules-count,unqualified-attributes,vendor-prefix,zero-units css/JSAV.css
47 |
48 | lint: jshint csslint
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #JSAV [](https://travis-ci.org/vkaravir/JSAV)
2 | This is the JSAV development library for creating Algorithm
3 | Visualizations in JavaScript.
4 |
5 | JSAV is a part of the [OpenDSA](https://github.com/OpenDSA/OpenDSA/) project. OpenDSA aims to create a
6 | complete hypertextbook for Data Structures and Algorithms along with
7 | the necessary supporting infrastructure. For more information about
8 | OpenDSA, see http://algoviz.org/ebook .
9 |
10 | ## License
11 |
12 | JSAV and OpenDSA are released under the MIT license. See the file
13 | MIT-license.txt included with this distribution.
14 |
15 | ## Documentation
16 | The JSAV documentation is available at [jsav.io](http://jsav.io/)
17 |
18 | ## Extensions
19 | JSAV is extandible, meaning that you can create your own data structures
20 | for it or use data structures created by someone else. OpenDSA contains
21 | several extensions which can be found
22 | [here](https://github.com/OpenDSA/OpenDSA/tree/master/DataStructures).
23 |
24 | ## For developers
25 |
26 | The day-to-day working JSAV repository is located at GitHub. For new
27 | developers who want to use the Github working version of JSAV:
28 |
29 | * Install Git
30 | * Check out the JSAV repository. For example, at the commandline you
31 | can do the following to create a new JSAV folder or directory:
32 | git clone git://github.com/vkaravir/JSAV.git JSAV
33 | (Note that this is a read-only URL. If you are joining the developer
34 | team, and you are not sufficiently familiar with Git to know what
35 | to do to set things up right to be able to push changes, talk to us
36 | about it.)
37 | * Go to the JSAV folder or directory that you just created and run:
38 | make
39 | This will "compile" the pieces together for you. At this point, you
40 | are ready to try out the examples or invoke your copy of JSAV in
41 | your own development projects.
42 |
43 | For SVN users new to git:
44 |
45 | * To "checkout" a new copy of the library, use "git clone".
46 | * To "update" your copy of the repository, use "git pull".
47 |
--------------------------------------------------------------------------------
/examples/slideshow.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | JSAV Slideshow Demonstration
5 |
6 |
17 |
18 |
19 |
JSAV Slideshow Demonstration
20 |
21 |
22 |
23 |
24 |
25 |
27 |
28 |
29 |
30 |
31 |
32 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/test/utils/qunit-assert-close.js:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2013 jQuery Foundation and other contributors
3 | http://jquery.com/
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | */
25 | QUnit.extend(QUnit.assert, {
26 | /**
27 | * Checks that the first two arguments are equal, or are numbers close enough to be considered equal
28 | * based on a specified maximum allowable difference.
29 | *
30 | * @example assert.close(3.141, Math.PI, 0.001);
31 | *
32 | * @param Number actual
33 | * @param Number expected
34 | * @param Number maxDifference (the maximum inclusive difference allowed between the actual and expected numbers)
35 | * @param String message (optional)
36 | */
37 | close: function(actual, expected, maxDifference, message) {
38 | var passes = (actual === expected) || Math.abs(actual - expected) <= maxDifference;
39 | QUnit.push(passes, actual, expected, message);
40 | },
41 |
42 | /**
43 | * Checks that the first two arguments are numbers with differences greater than the specified
44 | * minimum difference.
45 | *
46 | * @example assert.notClose(3.1, Math.PI, 0.001);
47 | *
48 | * @param Number actual
49 | * @param Number expected
50 | * @param Number minDifference (the minimum exclusive difference allowed between the actual and expected numbers)
51 | * @param String message (optional)
52 | */
53 | notClose: function(actual, expected, minDifference, message) {
54 | QUnit.push(Math.abs(actual - expected) > minDifference, actual, expected, message);
55 | }
56 | });
57 |
--------------------------------------------------------------------------------
/examples/binarytree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Example of Binary Tree
5 |
6 |
27 |
28 |
29 |
This is demonstration of supporting interactivity outside the
11 | context of a slideshow or standard proficiency exercise.
12 | (An example of a profiency exercise is shown in
13 | simple-exercise.html in this directory.)
14 | This might be useful, for example, in
15 | connection with using JSAV within Khan Academy exercises.
16 |
17 |
First we create and display a JSAV array with some random
18 | numbers. You can click on values in the array to highlight or
19 | unhighlight them. Your goal is to highlight (only) the array
20 | position with the biggest element.
This is a simple example of the JSAV matrix.
21 | It also illustrated updating slideshows interactively,
22 | on-the-fly.
23 | The example creates a sudoku game using a JSAV matrix.
24 | If you click on cells, they highlight the first time you click.
25 | Each click adds a new slide, which you can see by resetting the
26 | slideshow with the << control.
27 | View the source to see how this is done in CSS and JavaScript.
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
43 |
44 |
45 |
46 |
47 |
48 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/test/unit/exercise.js:
--------------------------------------------------------------------------------
1 | /*global JSAV,ok,test,module,strictEqual,deepEqual,equal,notEqual */
2 | (function() {
3 | "use strict";
4 |
5 | // The setup for an exercise which uses two arrays. The model answer
6 | // and the generated student answer differ in all but the first step.
7 | // In total there are four steps, and the differences are:
8 | // step 2: different indices are highlighted
9 | // step 3: different font-size is set for indices
10 | // step 4: a value in the array is set in the model solution
11 | // This setup can be used to test the compare option.
12 | function setupExercise(jsav, options) {
13 | var arr1, arr2;
14 | var init = function() {
15 | arr1 = jsav.ds.array([0, 1, 2, 3]);
16 | arr2 = jsav.ds.array([0, 1, 3, 2]);
17 | jsav.displayInit();
18 | return [arr1, arr2];
19 | };
20 | var model = function(modeljsav) {
21 | var arr1 = modeljsav.ds.array([0, 1, 2, 3]),
22 | arr2 = modeljsav.ds.array([0, 1, 3, 2]);
23 | modeljsav.displayInit();
24 | arr1.swap(1, 3);
25 | modeljsav.gradeableStep();
26 | arr1.highlight(0);
27 | modeljsav.gradeableStep();
28 | arr2.css(2, {color: "blue", fontSize: "20px"});
29 | modeljsav.gradeableStep();
30 | arr2.value(3, 3);
31 | modeljsav.gradeableStep();
32 | return [arr1, arr2];
33 | };
34 | var exercise = jsav.exercise(model, init, options);
35 | exercise.reset();
36 |
37 | arr1.swap(1, 3);
38 | jsav.gradeableStep();
39 | arr1.highlight(1);
40 | jsav.gradeableStep();
41 | arr2.css(2, {color: "blue", fontSize: "21px"});
42 | jsav.gradeableStep();
43 | return exercise;
44 | }
45 |
46 | module("exercise.grading", { });
47 | test("Exercise compare option (multiple structures)", function() {
48 | var jsav = new JSAV("emptycontainer");
49 | jsav.recorded();
50 | jsav.SPEED = 0;
51 | var exer = setupExercise(jsav, {feedback: "atend"});
52 | // test that the grading works properly and gives 3 correct when only values are compared
53 | strictEqual(exer.grade().correct, 3);
54 | strictEqual(exer.grade().total, 4); // just make sure the total step count matches
55 |
56 | // change the comparison to include fontSize
57 | exer.options.compare = [{}, {css: ["color", "fontSize"]}];
58 | strictEqual(exer.grade().correct, 2); // only two first steps are now correct
59 |
60 | // compare classes and the jsavhighlight class
61 | exer.options.compare = [{class: "jsavhighlight"}, {}];
62 | strictEqual(exer.grade().correct, 1); // only first step is now correct
63 |
64 | // incorrect compare option (should be an array), so expect only compare values
65 | exer.options.compare = {css: ["fontSize"]};
66 | strictEqual(exer.grade().correct, 3); // three steps correct based on values
67 | });
68 | }());
--------------------------------------------------------------------------------
/examples/keyvaluepair.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 |
9 |
10 |