-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vimscript/difference-of-squares: 1st iteration
- Loading branch information
Showing
10 changed files
with
342 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!coverage.py: This is a private format, don't read it directly!{"lines":{"/home/vpayno/git_vpayno/exercism-workspace/vimscript/difference-of-squares/difference_of_squares.vim":[14,18,24]},"file_tracers":{"/home/vpayno/git_vpayno/exercism-workspace/vimscript/difference-of-squares/difference_of_squares.vim":"covimerage.CoveragePlugin"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[run] | ||
plugins = covimerage | ||
data_file = .coverage_covimerage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
" .themisrc | ||
|
||
let g:repo_root = fnamemodify(expand('<sfile>'), ':h:h') | ||
|
||
call themis#option('exclude', g:repo_root . '/*.md') | ||
call themis#option('exclude', g:repo_root . '/*.vader') | ||
call themis#option('exclude', g:repo_root . '/*.txt') | ||
call themis#helper('command').with(themis#helper('assert')) | ||
|
||
if $PROFILE_LOG !=# '' | ||
execute 'profile' 'start' $PROFILE_LOG | ||
execute 'profile!' 'file' g:repo_root . '/*.vim' | ||
endif | ||
|
||
call themis#option('runtimepath', expand(g:repo_root)) | ||
|
||
" vim:ft=vim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" ?> | ||
<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="0.4286" lines-covered="3" lines-valid="7" timestamp="1713236661829" version="4.5.4"> | ||
<!-- Generated by coverage.py: https://coverage.readthedocs.io --> | ||
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd --> | ||
<sources> | ||
<source>/home/vpayno/git_vpayno/exercism-workspace/vimscript/difference-of-squares</source> | ||
</sources> | ||
<packages> | ||
<package branch-rate="0" complexity="0" line-rate="0.4286" name="."> | ||
<classes> | ||
<class branch-rate="0" complexity="0" filename="difference_of_squares.vim" line-rate="0.4286" name="difference_of_squares.vim"> | ||
<methods/> | ||
<lines> | ||
<line hits="1" number="14"/> | ||
<line hits="0" number="15"/> | ||
<line hits="1" number="18"/> | ||
<line hits="0" number="19"/> | ||
<line hits="0" number="21"/> | ||
<line hits="1" number="24"/> | ||
<line hits="0" number="25"/> | ||
</lines> | ||
</class> | ||
</classes> | ||
</package> | ||
</packages> | ||
</coverage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
SCRIPT /home/vpayno/git_vpayno/exercism-workspace/vimscript/difference-of-squares/difference_of_squares.vim | ||
Sourced 1 time | ||
Total time: 0.000017730 | ||
Self time: 0.000017730 | ||
|
||
count total (s) self (s) | ||
" | ||
" Find the difference between the square of the sum and the sum of the squares | ||
" of the first N natural numbers. | ||
" | ||
" Examples: | ||
" | ||
" :echo SquareOfSum(3) | ||
" 36 | ||
" :echo SumOfSquares(3) | ||
" 14 | ||
" :echo DifferenceOfSquares(3) | ||
" 22 | ||
" | ||
1 0.000003921 function! DifferenceOfSquares(number) abort | ||
return SquareOfSum(a:number) - SumOfSquares(a:number) | ||
endfunction | ||
|
||
1 0.000000749 function! SquareOfSum(number) abort | ||
let l:result = a:number * (a:number + 1) / 2 | ||
|
||
return l:result * l:result | ||
endfunction | ||
|
||
1 0.000000887 function! SumOfSquares(number) abort | ||
return a:number * (a:number + 1) * (2 * a:number + 1) / 6 | ||
endfunction | ||
|
||
FUNCTION SumOfSquares() | ||
Defined: ~/git_vpayno/exercism-workspace/vimscript/difference-of-squares/difference_of_squares.vim:24 | ||
Called 6 times | ||
Total time: 0.000010721 | ||
Self time: 0.000010721 | ||
|
||
count total (s) self (s) | ||
6 0.000010011 return a:number * (a:number + 1) * (2 * a:number + 1) / 6 | ||
|
||
FUNCTION DifferenceOfSquares() | ||
Defined: ~/git_vpayno/exercism-workspace/vimscript/difference-of-squares/difference_of_squares.vim:14 | ||
Called 3 times | ||
Total time: 0.000024316 | ||
Self time: 0.000009151 | ||
|
||
count total (s) self (s) | ||
3 0.000023471 0.000008306 return SquareOfSum(a:number) - SumOfSquares(a:number) | ||
|
||
FUNCTION SquareOfSum() | ||
Defined: ~/git_vpayno/exercism-workspace/vimscript/difference-of-squares/difference_of_squares.vim:18 | ||
Called 6 times | ||
Total time: 0.000018945 | ||
Self time: 0.000018945 | ||
|
||
count total (s) self (s) | ||
6 0.000010624 let l:result = a:number * (a:number + 1) / 2 | ||
|
||
6 0.000005401 return l:result * l:result | ||
|
||
FUNCTIONS SORTED ON TOTAL TIME | ||
count total (s) self (s) function | ||
3 0.000024316 0.000009151 DifferenceOfSquares() | ||
6 0.000018945 SquareOfSum() | ||
6 0.000010721 SumOfSquares() | ||
|
||
FUNCTIONS SORTED ON SELF TIME | ||
count total (s) self (s) function | ||
6 0.000018945 SquareOfSum() | ||
6 0.000010721 SumOfSquares() | ||
3 0.000024316 0.000009151 DifferenceOfSquares() | ||
|
126 changes: 126 additions & 0 deletions
126
vimscript/difference-of-squares/run-tests-vimscript.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
" themis.vimspec | ||
|
||
let s:suite = themis#suite('thesis tests') | ||
let s:assert = themis#helper('assert') | ||
|
||
source *.vim | ||
|
||
" SquareOfSum | ||
let g:test_cases1 = { | ||
\ 1: 1, | ||
\ 5: 225, | ||
\ 100: 25502500 | ||
\ } | ||
|
||
" SumOfSquares | ||
let g:test_cases2 = { | ||
\ 1: 1, | ||
\ 5: 55, | ||
\ 100: 338350 | ||
\ } | ||
|
||
" DifferenceOfSquares | ||
let g:test_cases3 = { | ||
\ 1: 0, | ||
\ 5: 170, | ||
\ 100: 25164150 | ||
\ } | ||
|
||
" The function name(my_test_1) will be a test name. | ||
function s:suite.test_SquareOfSum() | ||
let l:number = 0 | ||
let l:result = 0 | ||
|
||
for l:key in keys(g:test_cases1) | ||
let l:number = l:key | ||
let l:result = g:test_cases1[l:key] | ||
|
||
let l:got = SquareOfSum(l:number) | ||
let l:want = l:result | ||
|
||
" appending the number to the want/got values to make it easier to debug failures | ||
call s:assert.equals(l:number . ':' . l:want, l:number . ':' . l:got) | ||
endfor | ||
endfunction | ||
|
||
" The function name(my_test_1) will be a test name. | ||
function s:suite.test_SumOfSquares() | ||
let l:number = 0 | ||
let l:result = 0 | ||
|
||
for l:key in keys(g:test_cases2) | ||
let l:number = l:key | ||
let l:result = g:test_cases2[l:key] | ||
|
||
let l:got = SumOfSquares(l:number) | ||
let l:want = l:result | ||
|
||
" appending the number to the want/got values to make it easier to debug failures | ||
call s:assert.equals(l:number . ':' . l:want, l:number . ':' . l:got) | ||
endfor | ||
endfunction | ||
|
||
" The function name(my_test_1) will be a test name. | ||
function s:suite.test_DifferenceOfSquares() | ||
let l:number = 0 | ||
let l:result = 0 | ||
|
||
for l:key in keys(g:test_cases3) | ||
let l:number = l:key | ||
let l:result = g:test_cases3[l:key] | ||
|
||
let l:got = DifferenceOfSquares(l:number) | ||
let l:want = l:result | ||
|
||
" appending the number to the want/got values to make it easier to debug failures | ||
call s:assert.equals(l:number . ':' . l:want, l:number . ':' . l:got) | ||
endfor | ||
endfunction | ||
|
||
" vim: ft=vim |