Skip to content

Commit

Permalink
vimscript/leap: 1st iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Apr 10, 2024
1 parent ac6812f commit b39e1b9
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 2 deletions.
1 change: 1 addition & 0 deletions vimscript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@

- [hello-world](./hello-world/README.md)
- [raindrops](./raindrops/README.md)
- [leap](./leap/README.md)
1 change: 1 addition & 0 deletions vimscript/leap/.coverage_covimerage
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/leap/leap.vim":[5]},"file_tracers":{"/home/vpayno/git_vpayno/exercism-workspace/vimscript/leap/leap.vim":"covimerage.CoveragePlugin"}}
3 changes: 3 additions & 0 deletions vimscript/leap/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
plugins = covimerage
data_file = .coverage_covimerage
17 changes: 17 additions & 0 deletions vimscript/leap/.themisrc
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
10 changes: 9 additions & 1 deletion vimscript/leap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ Your task is to determine whether a given year is a leap year.

### Based on

CodeRanch Cattle Drive, Assignment 3 - https://coderanch.com/t/718816/Leap
CodeRanch Cattle Drive, Assignment 3 - https://coderanch.com/t/718816/Leap

### My Solution

- [my solution](./leap.vim)
- [vader tests](./leap.vader)
- [themis tests](./themis.vimspec)
- [themis profile](./profile.txt)
- [run-tests output](./run-tests-vimscript.txt)
29 changes: 29 additions & 0 deletions vimscript/leap/coverage.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" ?>
<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="0.1" lines-covered="1" lines-valid="10" timestamp="1712714319679" 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/leap</source>
</sources>
<packages>
<package branch-rate="0" complexity="0" line-rate="0.1" name=".">
<classes>
<class branch-rate="0" complexity="0" filename="leap.vim" line-rate="0.1" name="leap.vim">
<methods/>
<lines>
<line hits="1" number="5"/>
<line hits="0" number="7"/>
<line hits="0" number="8"/>
<line hits="0" number="10"/>
<line hits="0" number="11"/>
<line hits="0" number="14"/>
<line hits="0" number="15"/>
<line hits="0" number="18"/>
<line hits="0" number="19"/>
<line hits="0" number="22"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
16 changes: 15 additions & 1 deletion vimscript/leap/leap.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@
" and 0 otherwise.
"
function! LeapYear(year) abort
" the tests want 0->false, 1->true
let l:true = 1
let l:false = 0

" your implementation goes here
if a:year % 400 ==# 0
return l:true
endif

if a:year % 100 ==# 0
return l:false
endif

if a:year % 4 ==# 0
return l:true
endif

return l:false
endfunction
63 changes: 63 additions & 0 deletions vimscript/leap/profile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
SCRIPT /home/vpayno/git_vpayno/exercism-workspace/vimscript/leap/leap.vim
Sourced 1 time
Total time: 0.000014876
Self time: 0.000014876

count total (s) self (s)
"
" This function takes a year and returns 1 if it's a leap year
" and 0 otherwise.
"
1 0.000002322 function! LeapYear(year) abort
" the tests want 0->false, 1->true
let l:true = 1
let l:false = 0

if a:year % 400 ==# 0
return l:true
endif

if a:year % 100 ==# 0
return l:false
endif

if a:year % 4 ==# 0
return l:true
endif

return l:false
endfunction

FUNCTION LeapYear()
Defined: ~/git_vpayno/exercism-workspace/vimscript/leap/leap.vim:5
Called 5 times
Total time: 0.000036833
Self time: 0.000036833

count total (s) self (s)
" the tests want 0->false, 1->true
5 0.000004532 let l:true = 1
5 0.000004432 let l:false = 0

5 0.000004906 if a:year % 400 ==# 0
1 0.000000720 return l:true
4 0.000001581 endif

4 0.000003105 if a:year % 100 ==# 0
2 0.000001574 return l:false
2 0.000000666 endif

2 0.000001496 if a:year % 4 ==# 0
1 0.000000686 return l:true
1 0.000000338 endif

1 0.000000711 return l:false

FUNCTIONS SORTED ON TOTAL TIME
count total (s) self (s) function
5 0.000036833 LeapYear()

FUNCTIONS SORTED ON SELF TIME
count total (s) self (s) function
5 0.000036833 LeapYear()

117 changes: 117 additions & 0 deletions vimscript/leap/run-tests-vimscript.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Running automated test file(s):


===============================================================================

Running: vint --warning --verbose --enable-neovim .
vint DEBUG: checking: `leap.vim`
vint DEBUG: severity: WARNING
vint DEBUG: disabled: ProhibitAbbreviationOption
vint DEBUG: enabled: ProhibitAutocmdWithNoGroup
vint DEBUG: enabled: ProhibitCommandRelyOnUser
vint DEBUG: enabled: ProhibitCommandWithUnintendedSideEffect
vint DEBUG: enabled: ProhibitEncodingOptionAfterScriptEncoding
vint DEBUG: enabled: ProhibitEqualTildeOperator
vint DEBUG: enabled: ProhibitImplicitScopeBuiltinVariable
vint DEBUG: disabled: ProhibitImplicitScopeVariable
vint DEBUG: enabled: ProhibitInvalidMapCall
vint DEBUG: enabled: ProhibitMissingScriptEncoding
vint DEBUG: enabled: ProhibitNoAbortFunction
vint DEBUG: enabled: ProhibitSetNoCompatible
vint DEBUG: enabled: ProhibitUnnecessaryDoubleQuote
vint DEBUG: disabled: ProhibitUnusedVariable
vint DEBUG: enabled: ProhibitUsingUndeclaredVariable

real 0m0.239s
user 0m0.178s
sys 0m0.061s

===============================================================================

Running: vim '+source *vim | Vader!*' ./*.vader && echo Success || echo Failure
Vim: Warning: Output is not to a terminal
[?1049h[?1h=[?2004h[?25l"./leap.vader" 28L, 698B[?2004l[?1l>[?1049l[?25hVader note: cannot print to stderr reliably/directly. Please consider using Vim's -es/-Es option (mode=n).
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Jan 24 2024 13:08:58)
Included patches: 1-50
Compiled by vpayno@penguin
Huge version with GTK2 GUI. Features included (+) or not (-):
+acl +cmdline_hist +ex_extra +jumplist +mouse_dec +perl/dyn -sodium +textobjects +wildmenu
+arabic +cmdline_info +extra_search +keymap -mouse_gpm +persistent_undo +sound +textprop +windows
+autocmd +comments -farsi +lambda -mouse_jsbterm +popupwin +spell +timers +writebackup
+autochdir +conceal +file_in_path +langmap +mouse_netterm +postscript +startuptime +title +X11
-autoservername +cryptv +find_in_path +libcall +mouse_sgr +printer +statusline +toolbar +xattr
+balloon_eval +cscope +float +linebreak -mouse_sysmouse +profile -sun_workshop +user_commands -xfontset
+balloon_eval_term +cursorbind +folding +lispindent +mouse_urxvt -python +syntax +vartabs +xim
+browse +cursorshape -footer +listcmds +mouse_xterm +python3/dyn +tag_binary +vertsplit -xpm
++builtin_terms +dialog_con_gui +fork() +localmap +multi_byte +quickfix -tag_old_static +vim9script +xsmp_interact
+byte_offset +diff +gettext +lua/dyn +multi_lang +reltime -tag_any_white +viminfo +xterm_clipboard
+channel +digraphs -hangul_input +menu -mzscheme +rightleft +tcl/dyn +virtualedit -xterm_save
+cindent +dnd +iconv +mksession +netbeans_intg +ruby +termguicolors +visual
+clientserver -ebcdic +insert_expand +modify_fname +num64 +scrollbind +terminal +visualextra
+clipboard +emacs_tags +ipv6 +mouse +packages +signs +terminfo +vreplace
+cmdline_compl +eval +job +mouseshape +path_extra +smartindent +termresponse +wildignore
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "$VIM/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
defaults file: "$VIMRUNTIME/defaults.vim"
system menu file: "$VIMRUNTIME/menu.vim"
fall-back for $VIM: "/home/vpayno/.local/vim/usr/share/vim"
f-b for $VIMRUNTIME: "/home/vpayno/.local/vim/usr/share/vim/vim82"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -Wl,-E -rdynamic -Wl,-export-dynamic -L/usr/local/lib -Wl,--as-needed -o vim -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lharfbuzz -lfontconfig -lfreetype -lSM -lICE -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lselinux -lcanberra -lrt -ldl -L/home/vpayno/.local/activetcl-8.6/lib -ltclstub8.6 -ldl -lz -lpthread -lm -Wl,-rpath,/home/vpayno/.rbenv/versions/3.1.1/lib -L/home/vpayno/.rbenv/versions/3.1.1/lib -lruby -lm

Starting Vader: 1 suite(s), 5 case(s)
Starting Vader: /home/vpayno/git_vpayno/exercism-workspace/vimscript/leap/leap.vader
(1/5) [EXECUTE] year not divisible by 4: common year
(2/5) [EXECUTE] year divisible by 4, not divisible by 100: leap year
(3/5) [EXECUTE] year divisible by 100, not divisible by 400: common year
(4/5) [EXECUTE] year divisible by 400: leap year
(5/5) [EXECUTE] year divisible by 200, not divisible by 400: common year
Success/Total: 5/5
Success/Total: 5/5 (assertions: 5/5)
Elapsed time: 0.08 sec.
[?1049h[?1h=[?2004h[?2004l[?2004h[?2004l
[?2004l[?1l>[?1049l
real 0m2.493s
user 0m0.307s
sys 0m0.132s
Success

===============================================================================

Running: themis ./themis.vimspec
1..1
ok 1 - thesis tests test_leapyear

# tests 1
# passes 1

real 0m0.029s
user 0m0.016s
sys 0m0.008s

===============================================================================

Script line does not match function line, ignoring: ' " the tests want 0->false, 1->true' != ' " the tests want 0->false, 1->true'.
Could not find source for function: LeapYear
Writing coverage file .coverage_covimerage.
Coverage.py warning: Plugin file tracers (covimerage.CoveragePlugin) aren't supported with PyTracer
Name Stmts Miss Cover
------------------------------
leap.vim 10 9 10%
Coverage.py warning: Plugin file tracers (covimerage.CoveragePlugin) aren't supported with PyTracer

===============================================================================

Running: misspell .

real 0m0.021s
user 0m0.020s
sys 0m0.010s

===============================================================================

Expand Down
33 changes: 33 additions & 0 deletions vimscript/leap/themis.vimspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
" themis.vimspec

let s:suite = themis#suite('thesis tests')
let s:assert = themis#helper('assert')

source *.vim

let g:test_cases = {
\ '2015': 0,
\ '1996': 1,
\ '2100': 0,
\ '2000': 1,
\ '1800': 0
\ }

" The function name(my_test_1) will be a test name.
function s:suite.test_leapyear()
let l:year = 0
let l:result = 0

for l:key in keys(g:test_cases)
let l:year = str2nr(l:key)
let l:result = g:test_cases[l:key]

let l:got = LeapYear(l:year)
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:year . ':' . l:want, l:year . ':' . l:got)
endfor
endfunction

" vim: ft=vim

0 comments on commit b39e1b9

Please sign in to comment.