Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Task/CreateEventTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
test('Create event', function () {
"use strict";
var dateToString = function (currentTime) {
var month = currentTime.getMonth() + 1, day = currentTime.getDate(), year = currentTime.getFullYear();
return month + "/" + day + "/" + year;
}, undefinedDate, testEvent = new Event(undefinedDate);
equal(dateToString(testEvent.start), dateToString(new Date()));
testEvent = new Event();
equal(dateToString(testEvent.start), dateToString(new Date()));
testEvent = new Event(new Date(5), new Date(3));
ok(testEvent.start.getTime() < testEvent.end.getTime());
testEvent = new Event(new Date(1), new Date(2));
ok(testEvent.start.getTime() < testEvent.end.getTime());
});
17 changes: 17 additions & 0 deletions Task/EventLeaveMarkTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test('Leave Mark', function () {
"use strict";
var testEvent = Event(new Date(1), new Date(2), "Earth");
testEvent.leaveMark("No number");
equal(testEvent.stars, 0, 'Если звездочку передали в виде не числа, то 0');
var undefinedVar;
testEvent.leaveMark(undefinedVar);
equal(testEvent.stars, 0, 'Если звездочку забыли объявить, то 0');
testEvent.leaveMark(-1);
equal(testEvent.stars, 0, 'Звездочка не может быть меньше 0');
testEvent.leaveMark(6);
equal(testEvent.stars, 5, 'Звездочка не может быть больше 5');
testEvent.leaveMark(3);
equal(testEvent.stars, 3, '0-5 звездочка не изменяется, если целая');
testEvent.leaveMark(3.124);
equal(testEvent.stars, 3, 'Звездочки - Int');
});
25 changes: 25 additions & 0 deletions Task/EventSetLocationTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
test('Set location',function () {
"use strict";
var testEvent = Event(new Date(1), new Date(2), "Earth"),gps,name;
testEvent.setLocation(gps,"");
deepEqual(testEvent.location, {
"gps" : {"x": 0,"y": 0},
"nameLocation" : "Earth"
}, "GPS - некорректный => установить значения по умолчанию");
testEvent.setLocation("Not gps","");
deepEqual(testEvent.location, {
"gps" : {"x": 0,"y": 0},
"nameLocation" : "Earth"
}, "GPS - не содержит X или Y => установить значения по умолчанию");
testEvent.setLocation({"x": 0,"y": 0},[]);
deepEqual(testEvent.location, {
"gps" : {"x": 0,"y": 0},
"nameLocation" : "Earth"
}, "Название места не строка => установить значения по умолчанию");
testEvent.setLocation({"x": 1,"y": 2},"Moon");
deepEqual(testEvent.location, {
"gps" : {"x": 1,"y": 2},
"nameLocation" : "Moon"
}, "GPS - не содержит X или Y => установить значения по умолчанию");

});
70 changes: 70 additions & 0 deletions Task/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Creates an instance of Event.
*
* @param {start} - is start event
* @param {end} - is end event
* @param {location} - is location event
* @field {start} - is start event
* @field {end} - is end event
* @field {location} - location - is gps and name of event's place
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спасибо за ссылку. В 5том задании документацию исправлю.

* @field {participants} - participants - array of participants
* @field {stars} - is assess the importance of the event
* @field {cost} - is price for entry
* @method {setLocation} - is setter for location's field
* @method {leaveMark} - is setter for stars's field (0,1,2,3,4,5 - допустимые значения)
*/
function Event(start, end, location) {
"use strict";
var dateValidator = function (date) {
if (Object.prototype.toString.call(date) === "[object Date]") {
if (!isNaN(date.getTime())) {
return true;
}
}
return false;
}, tempDate;
if (!dateValidator(start)) {
start = new Date();
}
if (!dateValidator(end)) {
end = start;
}
if (start.getTime() > end.getTime()) {
tempDate = end;
end = start;
start = tempDate;
}
location = location || {
"gps": {x: 0, y: 0},
"nameLocation": "Earth"
};
return {
"start": start,
"end": end,
"location": location,
"participants": [],
"stars": 0,
"cost": 0,
"setLocation": function (gps, name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Помню я кому-то говорил про то, что нужно избавляться от генерации функций и выносить максимум в статические функции. Если это был ты, то забей ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Угу, в 3м задании уже исправлено

if (typeof gps !== "undefined" && typeof gps.x !== "undefined" && typeof gps.y !== "undefined" && typeof name === "string") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для большей читаемости.

if (typeof gps !== "undefined"  && 
    typeof gps.x !== "undefined" && 
    typeof gps.y !== "undefined" && 
    typeof name === "string") {

    // your stuff
}

this.location.gps = gps;
this.location.nameLocation = name;
} else {
this.location = {
"gps" : {"x": 0, "y": 0},
"nameLocation" : "Earth"
};
}
},
"leaveMark": function (stars) {
if (isNaN(parseFloat(stars)) || !isFinite(stars) || stars < 0) {
stars = 0;
}
if (stars > 5) {
stars = 5;
}
stars = (stars - (stars % 1)); //обрезаем дробную часть
this.stars = stars;
}
};
}
235 changes: 235 additions & 0 deletions Task/qunit-1.10.0.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
/**
* QUnit v1.10.0 - A JavaScript Unit Testing Framework
*
* http://qunitjs.com
*
* Copyright 2012 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/

/** Font Family and Sizes */

#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
}

#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-tests { font-size: smaller; }


/** Resets */

#qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
margin: 0;
padding: 0;
}


/** Header */

#qunit-header {
padding: 0.5em 0 0.5em 1em;

color: #8699a4;
background-color: #0d3349;

font-size: 1.5em;
line-height: 1em;
font-weight: normal;

border-radius: 5px 5px 0 0;
-moz-border-radius: 5px 5px 0 0;
-webkit-border-top-right-radius: 5px;
-webkit-border-top-left-radius: 5px;
}

#qunit-header a {
text-decoration: none;
color: #c2ccd1;
}

#qunit-header a:hover,
#qunit-header a:focus {
color: #fff;
}

#qunit-testrunner-toolbar label {
display: inline-block;
padding: 0 .5em 0 .1em;
}

#qunit-banner {
height: 5px;
}

#qunit-testrunner-toolbar {
padding: 0.5em 0 0.5em 2em;
color: #5E740B;
background-color: #eee;
overflow: hidden;
}

#qunit-userAgent {
padding: 0.5em 0 0.5em 2.5em;
background-color: #2b81af;
color: #fff;
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
}

#qunit-modulefilter-container {
float: right;
}

/** Tests: Pass/Fail */

#qunit-tests {
list-style-position: inside;
}

#qunit-tests li {
padding: 0.4em 0.5em 0.4em 2.5em;
border-bottom: 1px solid #fff;
list-style-position: inside;
}

#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
display: none;
}

#qunit-tests li strong {
cursor: pointer;
}

#qunit-tests li a {
padding: 0.5em;
color: #c2ccd1;
text-decoration: none;
}
#qunit-tests li a:hover,
#qunit-tests li a:focus {
color: #000;
}

#qunit-tests ol {
margin-top: 0.5em;
padding: 0.5em;

background-color: #fff;

border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}

#qunit-tests table {
border-collapse: collapse;
margin-top: .2em;
}

#qunit-tests th {
text-align: right;
vertical-align: top;
padding: 0 .5em 0 0;
}

#qunit-tests td {
vertical-align: top;
}

#qunit-tests pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}

#qunit-tests del {
background-color: #e0f2be;
color: #374e0c;
text-decoration: none;
}

#qunit-tests ins {
background-color: #ffcaca;
color: #500;
text-decoration: none;
}

/*** Test Counts */

#qunit-tests b.counts { color: black; }
#qunit-tests b.passed { color: #5E740B; }
#qunit-tests b.failed { color: #710909; }

#qunit-tests li li {
padding: 5px;
background-color: #fff;
border-bottom: none;
list-style-position: inside;
}

/*** Passing Styles */

#qunit-tests li li.pass {
color: #3c510c;
background-color: #fff;
border-left: 10px solid #C6E746;
}

#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
#qunit-tests .pass .test-name { color: #366097; }

#qunit-tests .pass .test-actual,
#qunit-tests .pass .test-expected { color: #999999; }

#qunit-banner.qunit-pass { background-color: #C6E746; }

/*** Failing Styles */

#qunit-tests li li.fail {
color: #710909;
background-color: #fff;
border-left: 10px solid #EE5757;
white-space: pre;
}

#qunit-tests > li:last-child {
border-radius: 0 0 5px 5px;
-moz-border-radius: 0 0 5px 5px;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
}

#qunit-tests .fail { color: #000000; background-color: #EE5757; }
#qunit-tests .fail .test-name,
#qunit-tests .fail .module-name { color: #000000; }

#qunit-tests .fail .test-actual { color: #EE5757; }
#qunit-tests .fail .test-expected { color: green; }

#qunit-banner.qunit-fail { background-color: #EE5757; }


/** Result */

#qunit-testresult {
padding: 0.5em 0.5em 0.5em 2.5em;

color: #2b81af;
background-color: #D2E0E6;

border-bottom: 1px solid white;
}
#qunit-testresult .module-name {
font-weight: bold;
}

/** Fixture */

#qunit-fixture {
position: absolute;
top: -10000px;
left: -10000px;
width: 1000px;
height: 1000px;
}
Loading