Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vimscript leap #353

Merged
merged 2 commits into from
Apr 10, 2024
Merged
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
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
24 changes: 24 additions & 0 deletions vimscript/leap/.exercism/config.json
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions vimscript/leap/.exercism/metadata.json
Original file line number Diff line number Diff line change
@@ -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}
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
52 changes: 52 additions & 0 deletions vimscript/leap/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Help

## Running the tests

Open your solution:

```bash
$ vim <exercise>.vim
```

Source the current file to make its global functions available to Vim:

```
:source %
```

Run the tests:

```
:Vader <exercise>.vader
```

Replace `<exercise>` 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.
49 changes: 49 additions & 0 deletions vimscript/leap/README.md
Original file line number Diff line number Diff line change
@@ -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)
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>
28 changes: 28 additions & 0 deletions vimscript/leap/leap.vader
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions vimscript/leap/leap.vim
Original file line number Diff line number Diff line change
@@ -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
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()

Loading
Loading