diff --git a/vimscript/README.md b/vimscript/README.md index 16ef8f08..fa6d81c0 100644 --- a/vimscript/README.md +++ b/vimscript/README.md @@ -16,3 +16,4 @@ - [hello-world](./hello-world/README.md) - [raindrops](./raindrops/README.md) +- [leap](./leap/README.md) diff --git a/vimscript/leap/.coverage_covimerage b/vimscript/leap/.coverage_covimerage new file mode 100644 index 00000000..1cd2e329 --- /dev/null +++ b/vimscript/leap/.coverage_covimerage @@ -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"}} \ No newline at end of file diff --git a/vimscript/leap/.coveragerc b/vimscript/leap/.coveragerc new file mode 100644 index 00000000..8cddf91c --- /dev/null +++ b/vimscript/leap/.coveragerc @@ -0,0 +1,3 @@ +[run] +plugins = covimerage +data_file = .coverage_covimerage diff --git a/vimscript/leap/.exercism/config.json b/vimscript/leap/.exercism/config.json new file mode 100644 index 00000000..ab09499d --- /dev/null +++ b/vimscript/leap/.exercism/config.json @@ -0,0 +1,24 @@ +{ + "authors": [ + "mhinz" + ], + "contributors": [ + "kotp", + "kytrinyx", + "thinca" + ], + "files": { + "solution": [ + "leap.vim" + ], + "test": [ + "leap.vader" + ], + "example": [ + ".meta/example.vim" + ] + }, + "blurb": "Determine whether a given year is a leap year.", + "source": "CodeRanch Cattle Drive, Assignment 3", + "source_url": "https://coderanch.com/t/718816/Leap" +} diff --git a/vimscript/leap/.exercism/metadata.json b/vimscript/leap/.exercism/metadata.json new file mode 100644 index 00000000..9c92474d --- /dev/null +++ b/vimscript/leap/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"vimscript","exercise":"leap","id":"88445f462f96466094d5e1fffe6400a5","url":"https://exercism.org/tracks/vimscript/exercises/leap","handle":"vpayno","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/vimscript/leap/.themisrc b/vimscript/leap/.themisrc new file mode 100644 index 00000000..5c43c80e --- /dev/null +++ b/vimscript/leap/.themisrc @@ -0,0 +1,17 @@ +" .themisrc + +let g:repo_root = fnamemodify(expand(''), ':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 diff --git a/vimscript/leap/HELP.md b/vimscript/leap/HELP.md new file mode 100644 index 00000000..59522029 --- /dev/null +++ b/vimscript/leap/HELP.md @@ -0,0 +1,52 @@ +# Help + +## Running the tests + +Open your solution: + +```bash +$ vim .vim +``` + +Source the current file to make its global functions available to Vim: + +``` +:source % +``` + +Run the tests: + +``` +:Vader .vader +``` + +Replace `` with your exercise's name. + +## Submitting your solution + +You can submit your solution using the `exercism submit leap.vim` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Vim script track's documentation](https://exercism.org/docs/tracks/vimscript) +- The [Vim script track's programming category on the forum](https://forum.exercism.org/c/programming/vimscript) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Learn Vimscript the Hard Way](http://learnvimscriptthehardway.stevelosh.com) +- [IBM DeveloperWorks: Scripting the Vim + editor](http://www.ibm.com/developerworks/views/linux/libraryview.jsp?sort_order=asc&sort_by=Title&search_by=scripting+the+vim+editor) +- [/r/vimscript](https://www.reddit.com/r/vimscript) is the Vimscript subreddit. +- [StackOverflow](http://stackoverflow.com/) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/vimscript/leap/README.md b/vimscript/leap/README.md new file mode 100644 index 00000000..4cd96574 --- /dev/null +++ b/vimscript/leap/README.md @@ -0,0 +1,49 @@ +# Leap + +Welcome to Leap on Exercism's Vim script Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Introduction + +A leap year (in the Gregorian calendar) occurs: + +- In every year that is evenly divisible by 4. +- Unless the year is evenly divisible by 100, in which case it's only a leap year if the year is also evenly divisible by 400. + +Some examples: + +- 1997 was not a leap year as it's not divisible by 4. +- 1900 was not a leap year as it's not divisible by 400. +- 2000 was a leap year! + +~~~~exercism/note +For a delightful, four-minute explanation of the whole phenomenon of leap years, check out [this YouTube video](https://www.youtube.com/watch?v=xX96xng7sAE). +~~~~ + +## Instructions + +Your task is to determine whether a given year is a leap year. + +## Source + +### Created by + +- @mhinz + +### Contributed to by + +- @kotp +- @kytrinyx +- @thinca + +### Based on + +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) diff --git a/vimscript/leap/coverage.xml b/vimscript/leap/coverage.xml new file mode 100644 index 00000000..6e4364bb --- /dev/null +++ b/vimscript/leap/coverage.xml @@ -0,0 +1,29 @@ + + + + + + /home/vpayno/git_vpayno/exercism-workspace/vimscript/leap + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vimscript/leap/leap.vader b/vimscript/leap/leap.vader new file mode 100644 index 00000000..ebc84883 --- /dev/null +++ b/vimscript/leap/leap.vader @@ -0,0 +1,28 @@ +" +" Version: 1.4.0 +" + +Execute (year not divisible by 4: common year): + let year = 2015 + let expected = 0 + AssertEqual expected, LeapYear(year) + +Execute (year divisible by 4, not divisible by 100: leap year): + let year = 1996 + let expected = 1 + AssertEqual expected, LeapYear(year) + +Execute (year divisible by 100, not divisible by 400: common year): + let year = 2100 + let expected = 0 + AssertEqual expected, LeapYear(year) + +Execute (year divisible by 400: leap year): + let year = 2000 + let expected = 1 + AssertEqual expected, LeapYear(year) + +Execute (year divisible by 200, not divisible by 400: common year): + let year = 1800 + let expected = 0 + AssertEqual expected, LeapYear(year) diff --git a/vimscript/leap/leap.vim b/vimscript/leap/leap.vim new file mode 100644 index 00000000..ea57b5f2 --- /dev/null +++ b/vimscript/leap/leap.vim @@ -0,0 +1,23 @@ +" +" This function takes a year and returns 1 if it's a leap year +" and 0 otherwise. +" +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 diff --git a/vimscript/leap/profile.txt b/vimscript/leap/profile.txt new file mode 100644 index 00000000..a3155b9d --- /dev/null +++ b/vimscript/leap/profile.txt @@ -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() + diff --git a/vimscript/leap/run-tests-vimscript.txt b/vimscript/leap/run-tests-vimscript.txt new file mode 100644 index 00000000..e53a45de --- /dev/null +++ b/vimscript/leap/run-tests-vimscript.txt @@ -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 + +=============================================================================== + diff --git a/vimscript/leap/themis.vimspec b/vimscript/leap/themis.vimspec new file mode 100644 index 00000000..cf38fc04 --- /dev/null +++ b/vimscript/leap/themis.vimspec @@ -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