Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DatabaseTest
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hans-Jeiger Gram
DatabaseTest
Commits
b867af24
Commit
b867af24
authored
6 years ago
by
nilstes
Browse files
Options
Downloads
Patches
Plain Diff
ferdig med eksempel?
parent
c2cc6d8e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
dao/calculator.js
+36
-0
36 additions, 0 deletions
dao/calculator.js
dao/calculator.test.js
+36
-0
36 additions, 0 deletions
dao/calculator.test.js
dao/dum.test.js
+49
-0
49 additions, 0 deletions
dao/dum.test.js
dao/sum.test.js
+9
-11
9 additions, 11 deletions
dao/sum.test.js
server.js
+6
-6
6 additions, 6 deletions
server.js
with
136 additions
and
17 deletions
dao/calculator.js
0 → 100644
+
36
−
0
View file @
b867af24
module
.
exports
=
class
Calculator
{
constructor
()
{}
calculate
(
expression
)
{
let
pos
=
expression
.
indexOf
(
"
+
"
);
if
(
pos
>=
0
)
{
return
(
this
.
calculate
(
expression
.
substr
(
0
,
pos
))
+
this
.
calculate
(
expression
.
substr
(
pos
+
1
))
);
}
else
{
pos
=
expression
.
indexOf
(
"
-
"
);
if
(
pos
>=
0
)
{
return
(
this
.
calculate
(
expression
.
substr
(
0
,
pos
))
-
this
.
calculate
(
expression
.
substr
(
pos
+
1
))
);
}
else
{
// Remove ALL whitespaces
expression
=
expression
.
replace
(
/
\s
+/g
,
""
);
if
(
expression
===
""
)
{
return
0
;
}
let
num
=
Number
(
expression
);
if
(
!
Number
.
isInteger
(
num
))
{
console
.
log
(
"
'
"
+
expression
+
"
' is not an integer
"
);
throw
new
Error
(
"
'
"
+
expression
+
"
' is not an integer
"
);
}
else
{
return
num
;
}
}
}
return
0
;
}
};
This diff is collapsed.
Click to expand it.
dao/calculator.test.js
0 → 100644
+
36
−
0
View file @
b867af24
const
Calculator
=
require
(
"
./calculator
"
);
let
calc
=
new
Calculator
();
beforeEach
(()
=>
{
console
.
log
(
"
calculator.test: beforeEach
"
);
});
afterEach
(()
=>
{
console
.
log
(
"
calculator.test: afterEach
"
);
});
beforeAll
(()
=>
{
console
.
log
(
"
calculator.test: beforeAll
"
);
});
afterAll
(()
=>
{
console
.
log
(
"
calculator.test: afterAll
"
);
});
test
(
"
test plus and minus with any number of arguments
"
,
()
=>
{
expect
(
calc
.
calculate
(
""
)).
toBe
(
0
);
expect
(
calc
.
calculate
(
"
2
"
)).
toBe
(
2
);
expect
(
calc
.
calculate
(
"
2+2
"
)).
toBe
(
4
);
expect
(
calc
.
calculate
(
"
2+4+3-3+5
"
)).
toBe
(
11
);
});
test
(
"
test that whitespace is allowed
"
,
()
=>
{
expect
(
calc
.
calculate
(
"
\t\n\r
2 +
\n
3
"
)).
toBe
(
5
);
});
test
(
"
test that only digits and plus and minus and whitespace is allowed
"
,
()
=>
{
let
illegal
=
[
"
1.2
"
,
"
1,2
"
,
"
1/2
"
,
"
1*2
"
,
"
1 plus 2
"
];
for
(
i
in
illegal
)
{
expect
(()
=>
calc
.
calculate
(
illegal
[
i
])).
toThrow
();
}
});
This diff is collapsed.
Click to expand it.
dao/dum.test.js
0 → 100644
+
49
−
0
View file @
b867af24
beforeEach
(()
=>
{
console
.
log
(
"
dum.test: beforeEach
"
);
});
afterEach
(()
=>
{
console
.
log
(
"
dum.test: afterEach
"
);
});
beforeAll
(()
=>
{
console
.
log
(
"
dum.test: beforeAll
"
);
});
afterAll
(()
=>
{
console
.
log
(
"
dum.test: afterAll
"
);
});
test
(
"
test at 1 er 1
"
,
()
=>
{
console
.
log
(
"
dum.test: test 1
"
);
expect
(
1
).
toBe
(
1
);
});
test
(
"
test at 2 er 2
"
,
()
=>
{
console
.
log
(
"
dum.test: test 2
"
);
expect
(
2
).
toBe
(
2
);
});
test
(
"
test alle expects
"
,
()
=>
{
// Kjør kode
// før vi verifiserer resultatet
expect
(
2
+
2
).
toBe
(
4
);
expect
(
2
+
2
).
toEqual
(
4
);
expect
(
1
+
1
).
not
.
toBe
(
0
);
expect
(
"
data
"
).
toEqual
(
"
data
"
);
expect
(
true
).
toBeTruthy
();
expect
(
false
).
not
.
toBeTruthy
();
expect
(
"
1
"
).
toBeDefined
();
expect
(
"
1
"
).
not
.
toBeUndefined
();
expect
(
2
).
toBeLessThan
(
5
);
expect
(
"
Christoph
"
).
toMatch
(
/stop/
);
// Regular expression
});
someCode
=
()
=>
{
throw
Error
(
"
Feil
"
);
};
test
(
"
test exception
"
,
()
=>
{
expect
(
someCode
).
toThrow
();
});
This diff is collapsed.
Click to expand it.
dao/sum.test.js
+
9
−
11
View file @
b867af24
const
sum
=
require
(
'
./sum
'
);
const
sum
=
require
(
"
./sum
"
);
/*
beforeEach
(()
=>
{
initializeCityDatabase(
);
console
.
log
(
"
sum.test: beforeEach
"
);
});
afterEach
(()
=>
{
c
learCityDatabase(
);
c
onsole
.
log
(
"
sum.test: afterEach
"
);
});
test('city database has Vienna',
() => {
expect(isCity('Vienna')).toBeTruthy(
);
beforeAll
(
()
=>
{
console
.
log
(
"
sum.test: beforeAll
"
);
});
test('city database has San Juan',
() => {
expect(isCity('San Juan')).toBeTruthy(
);
});
*/
afterAll
(
()
=>
{
console
.
log
(
"
sum.test: afterAll
"
);
});
test
(
"
adds 1 + 2 to equal 3
"
,
()
=>
{
console
.
log
(
"
Running simple test
"
);
expect
(
sum
(
1
,
2
)).
toBe
(
3
);
});
\ No newline at end of file
});
This diff is collapsed.
Click to expand it.
server.js
+
6
−
6
View file @
b867af24
...
...
@@ -19,25 +19,25 @@ let personDao = new PersonDao(pool);
app
.
get
(
"
/person
"
,
(
req
,
res
)
=>
{
console
.
log
(
"
/person: fikk request fra klient
"
);
personDao
.
getAll
((
status
,
json
)
=>
{
personDao
.
getAll
((
status
,
data
)
=>
{
res
.
status
(
status
);
res
.
json
(
json
);
res
.
json
(
data
);
});
});
app
.
get
(
"
/person/:personId
"
,
(
req
,
res
)
=>
{
console
.
log
(
"
/person/:personId: fikk request fra klient
"
);
personDao
.
getOne
(
req
.
params
.
personId
,
(
status
,
json
)
=>
{
personDao
.
getOne
(
req
.
params
.
personId
,
(
status
,
data
)
=>
{
res
.
status
(
status
);
res
.
json
(
json
);
res
.
json
(
data
);
});
});
app
.
post
(
"
/person
"
,
(
req
,
res
)
=>
{
console
.
log
(
"
Fikk POST-request fra klienten
"
);
personDao
.
createOne
(
req
.
body
,
(
status
,
json
)
=>
{
personDao
.
createOne
(
req
.
body
,
(
status
,
data
)
=>
{
res
.
status
(
status
);
res
.
json
(
json
);
res
.
json
(
data
);
});
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment