diff options
author | Juan Carlos <juancarlospaco@gmail.com> | 2020-04-01 14:39:58 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-01 19:39:58 +0200 |
commit | 48169847265e13d3b12d670230ad6d33a9d384cc (patch) | |
tree | 8028b0bea953b5cecefb6ba4353546b529c19bdd /lib | |
parent | 484548c784f69cadc1f6480a24e99183a0e6a930 (diff) | |
download | Nim-48169847265e13d3b12d670230ad6d33a9d384cc.tar.gz |
Documentation, add more examples (#13825)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/posix/inotify.nim | 10 | ||||
-rw-r--r-- | lib/pure/concurrency/cpuinfo.nim | 8 | ||||
-rw-r--r-- | lib/pure/osproc.nim | 1 | ||||
-rw-r--r-- | lib/pure/stats.nim | 15 | ||||
-rw-r--r-- | lib/system/assertions.nim | 4 |
5 files changed, 26 insertions, 12 deletions
diff --git a/lib/posix/inotify.nim b/lib/posix/inotify.nim index f88e48a2d..9728b749b 100644 --- a/lib/posix/inotify.nim +++ b/lib/posix/inotify.nim @@ -70,3 +70,13 @@ proc inotify_add_watch*(fd: cint; name: cstring; mask: uint32): cint{. # Remove the watch specified by WD from the inotify instance FD. proc inotify_rm_watch*(fd: cint; wd: cint): cint{.cdecl, importc: "inotify_rm_watch", header: "<sys/inotify.h>".} + + +runnableExamples: + when defined(linux): + block: + let inoty: cint = inotify_init() ## Create 1 Inotify. + doAssert inoty >= 0 ## Check for errors. + let watchdoge: cint = inotify_add_watch(inoty, ".", IN_ALL_EVENTS) ## Add directory to watchdog. + doAssert watchdoge >= 0 ## Check for errors. + doAssert inotify_rm_watch(inoty, watchdoge) >= 0 ## Remove directory from the watchdog diff --git a/lib/pure/concurrency/cpuinfo.nim b/lib/pure/concurrency/cpuinfo.nim index 51f80b103..3e5695360 100644 --- a/lib/pure/concurrency/cpuinfo.nim +++ b/lib/pure/concurrency/cpuinfo.nim @@ -49,9 +49,6 @@ when defined(haiku): proc countProcessors*(): int {.rtl, extern: "ncpi$1".} = ## returns the number of the processors/cores the machine has. ## Returns 0 if it cannot be detected. - ## - ## .. code-block:: nim - ## block: doAssert countProcessors() >= 0 when defined(windows): type SYSTEM_INFO {.final, pure.} = object @@ -98,3 +95,8 @@ proc countProcessors*(): int {.rtl, extern: "ncpi$1".} = else: result = sysconf(SC_NPROCESSORS_ONLN) if result <= 0: result = 0 + + +runnableExamples: + block: + doAssert countProcessors() > 0 diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 9840973b2..92575e5f3 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -293,6 +293,7 @@ proc errorHandle*(p: Process): FileHandle {.rtl, extern: "nosp$1", proc countProcessors*(): int {.rtl, extern: "nosp$1".} = ## Returns the number of the processors/cores the machine has. ## Returns 0 if it cannot be detected. + ## It is implemented just calling `cpuinfo.countProcessors`. result = cpuinfo.countProcessors() proc execProcesses*(cmds: openArray[string], diff --git a/lib/pure/stats.nim b/lib/pure/stats.nim index ac48d9eee..8684cb60a 100644 --- a/lib/pure/stats.nim +++ b/lib/pure/stats.nim @@ -327,13 +327,14 @@ runnableExamples: var statistics: RunningStat ## Must be "var" statistics.push(@[1.0, 2.0, 1.0, 4.0, 1.0, 4.0, 1.0, 2.0]) doAssert statistics.n == 8 - doAssert statistics.mean() is SomeFloat - doAssert statistics.variance() is SomeFloat - doAssert statistics.varianceS() is SomeFloat - doAssert statistics.skewness() is SomeFloat - doAssert statistics.skewnessS() is SomeFloat - doAssert statistics.kurtosis() is SomeFloat - doAssert statistics.kurtosisS() is SomeFloat + template `===`(a, b: float): bool = (abs(a - b) < 1e-9) + doAssert statistics.mean() === 2.0 + doAssert statistics.variance() === 1.5 + doAssert statistics.varianceS() === 1.714285714285715 + doAssert statistics.skewness() === 0.8164965809277261 + doAssert statistics.skewnessS() === 1.018350154434631 + doAssert statistics.kurtosis() === -1.0 + doAssert statistics.kurtosisS() === -0.7000000000000008 when isMainModule: diff --git a/lib/system/assertions.nim b/lib/system/assertions.nim index 13836a540..64ed44ea7 100644 --- a/lib/system/assertions.nim +++ b/lib/system/assertions.nim @@ -50,7 +50,7 @@ template assert*(cond: untyped, msg = "") = ## `command line switches <nimc.html#compiler-usage-command-line-switches>`_. ## ## .. code-block:: nim - ## static: assert 1 == 9, "This works when not built with -d:danger or --assertions:off" + ## static: assert 1 == 9, "This assertion generates code when not built with -d:danger or --assertions:off" const expr = astToStr(cond) assertImpl(cond, msg, expr, compileOption("assertions")) @@ -58,7 +58,7 @@ template doAssert*(cond: untyped, msg = "") = ## Similar to ``assert`` but is always turned on regardless of ``--assertions``. ## ## .. code-block:: nim - ## static: assert 1 == 9, "This works when built with/without -d:danger or --assertions:off" + ## static: doAssert 1 == 9, "This assertion generates code when built with/without -d:danger or --assertions:off" const expr = astToStr(cond) assertImpl(cond, msg, expr, true) |