1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
pub mod tdd {
    pub mod unit {

        pub const IS_OK: &str = "The result match true";
        pub const IS_KO: &str = "The result match false";
        pub const IS_EQUALS: &str = "The values are equals";
        pub const IS_UNEQUALS: &str = "The values are unequals";
        pub const IS_BETWEEN: &str = "The values are between the expected values";
        pub const IS_INFERIOR: &str = "The value are inferior to the expected value";
        pub const IS_SUPERIOR: &str = "The value are superior to the expected value";
        pub const IS_EMPTY: &str = "The value is empty";
        pub const IS_DIRECTORY: &str = "The directory exist";
        pub const IS_FILE: &str = "The file exist";
        pub const IS_FULL: &str = "The value is at this maximum value";
        pub const IS_PRIME: &str = "The value is a prime number";
        pub const IS_PAIR: &str = "The value is a pair number";
        pub const IS_START_WITH: &str = "The value start with the expected value";
        pub const IS_FINNISH_WITH: &str = "The value finnish with the expected value";
        pub const IS_IMPAIR: &str = "The value is not a pair number";
        pub const IS_CONTAINS: &str = "The value contains the expected value";
        pub const IS_ABSOLUTE: &str = "The path is absolute";
        pub const IS_EXISTS: &str = "The path exists";
        pub const IS_RELATIVE: &str = "The path is relative";
        pub const IS_SYMLINK: &str = "The path is a symlink";
        pub const IS_EXECUTABLE: &str = "The file is executable";
        pub const THEORY_IS_TRUE: &str = "The theory is true";
        pub const THEORY_IS_FALSE: &str = "The theory is false";
        pub const IS_NOT_EXECUTABLE: &str = "The file is not executable";
        pub const IS_NOT_SYMLINK: &str = "The path is a symlink";
        pub const IS_NOT_RELATIVE: &str = "The path is not relative";
        pub const IS_NOT_EXISTS: &str = "The path not exists";
        pub const IS_NOT_ABSOLUTE: &str = "The path is not absolute";
        pub const IS_NOT_FINNISH_WITH: &str = "The value don't finnish with the expected value";
        pub const IS_NOT_CONTAINS: &str = "The value not contains the expected value";
        pub const IS_NOT_PRIME: &str = "The value is not a prime number";
        pub const IS_NOT_FULL: &str = "The value is not at this maximum value";
        pub const IS_NOT_FILE: &str = "The file not exist";
        pub const IS_NOT_DIRECTORY: &str = "The directory not exist";
        pub const IS_NOT_EMPTY: &str = "The value is not empty";
        pub const IS_NOT_BETWEEN: &str = "The values aren't between the expected values";
        pub const IS_NOT_START_WITH: &str = "The value no start with the expected value";

        pub const PROGRESS: u64 = 500;
        pub const NO_PROGRESS: u64 = 0;

        pub enum Style {
            POINT,
            ASTERIX,
            OKAY,
        }
        use colored_truecolor::Colorize;
        use is_executable::IsExecutable;
        use std::cell::Cell;
        use std::ops::Add;
        use std::path::Path;
        use std::thread::sleep;
        use std::time::{Duration, Instant};

        pub struct Unit {
            description: String,
            assertions: Cell<usize>,
            failures: Cell<usize>,
            start: Instant,
            tdd: Cell<usize>,
            sleep_time: u64,
            style: Style,
        }

        ///
        /// # To run unit test
        ///
        impl Unit {
            ///
            /// Get all assertions number
            ///
            fn assertions(&mut self) -> usize {
                self.assertions.get()
            }

            ///
            /// Get all failures number
            ///
            fn failures(&mut self) -> usize {
                self.failures.get()
            }

            pub fn exe(&mut self, filename: &str) -> &mut Unit {
                self.assert(
                    Path::new(filename).is_executable(),
                    IS_EXECUTABLE,
                    IS_NOT_EXECUTABLE,
                )
            }
            ///
            /// Run a test
            ///
            /// - `tdd` The test to execute
            /// - `s`   The success output
            /// - `f`   The failure output
            ///
            fn assert(&mut self, tdd: bool, s: &str, f: &str) -> &mut Unit {
                self.tdd.set(self.tdd.get() + 1);

                match self.style {
                    Style::POINT => {
                        if tdd {
                            self.assertions.set(self.assertions.get() + 1);
                            print!("{}", ".".magenta().bold());
                        } else {
                            self.failures.set(self.failures.get() + 1);
                            print!("{}", "F".magenta().bold());
                        }
                        sleep(Duration::from_millis(self.sleep_time));
                    }
                    Style::OKAY => {
                        if tdd {
                            self.assertions.set(self.assertions.get() + 1);
                            println!(
                                "{}  {}  {} {}\n",
                                "[".white().bold(),
                                "OK".green().bold(),
                                "]".white().bold(),
                                s.blue().bold()
                            );
                        } else {
                            self.failures.set(self.failures.get() + 1);
                            println!(
                                "{}  {}  {} {}\n",
                                "[".white().bold(),
                                "KO".red().bold(),
                                "]".white().bold(),
                                f.yellow().bold()
                            );
                        }
                        sleep(Duration::from_millis(self.sleep_time));
                    }
                    Style::ASTERIX => {
                        if tdd {
                            self.assertions.set(self.assertions.get() + 1);
                            println!("{} {}\n", "*".green().bold(), s.blue().bold());
                        } else {
                            self.failures.set(self.failures.get() + 1);
                            println!("{} {}\n", "*".red().bold(), f.yellow().bold());
                        }
                        sleep(Duration::from_millis(self.sleep_time));
                    }
                }
                sleep(Duration::from_millis(self.sleep_time));
                self
            }

            ///
            ///
            /// # Group test in a function                                                                                                         
            ///  
            /// - `description` The group test description
            /// - `it`          The callback to execute
            ///
            pub fn describe(
                &mut self,
                description: &str,
                it: fn(&mut Unit) -> &mut Unit,
            ) -> &mut Unit {
                self.title(description);
                it(self)
            }

            pub fn title(&mut self, description: &str) {
                if self.assertions() == 0 && self.failures() == 0 {
                    println!("{}\n", description.blue().bold());
                } else {
                    println!("\n\n{}\n", description.blue().bold());
                }
            }
            pub fn theory(&mut self, description: &str, it: fn() -> bool) -> &mut Unit {
                self.title(description);
                self.assert(it(), THEORY_IS_TRUE, THEORY_IS_FALSE)
            }

            pub fn chaos(&mut self, description: &str, it: fn() -> bool) -> &mut Unit {
                self.title(description);
                self.assert(!it(), THEORY_IS_FALSE, THEORY_IS_TRUE)
            }

            ///
            ///
            /// # Unit constructor
            ///
            /// - `description`     The unit test description
            /// - `time`            The sleep time
            ///
            ///
            pub fn new(description: &str, time: u64, s: Style) -> Unit {
                println!("\n{}\n", description.magenta().bold());

                Self {
                    description: description.to_string(),
                    assertions: Cell::new(0),
                    failures: Cell::new(0),
                    start: Instant::now(),
                    tdd: Cell::new(0),
                    sleep_time: time,
                    style: s,
                }
            }

            ///
            ///
            /// End of the tests
            ///
            pub fn end(&mut self) -> Result<String, String> {
                let asserts = self.assertions();
                let fails = self.failures();

                println!(
                    "\n\n{} : {}  {} : {}  {} : {} {} : {}\n",
                    "Assertions".blue().bold(),
                    asserts.to_string().green().bold(),
                    "Failures".blue().bold(),
                    fails.to_string().red().bold(),
                    "Execution time".blue().bold(),
                    self.start
                        .elapsed()
                        .as_millis()
                        .to_string()
                        .add(" ms")
                        .magenta()
                        .bold(),
                    "All tests executed".blue().bold(),
                    self.tdd.get().to_string().cyan().bold()
                );

                return if self.failures() >= 1 {
                    Err(String::from(self.description.as_str()))
                } else {
                    Ok(String::from(self.description.as_str()))
                };
            }

            ///
            ///
            /// # Check if all values are equals to true
            ///
            /// - `b`   A value to check
            ///
            pub fn ok(&mut self, b: bool) -> &mut Unit {
                self.assert(b, IS_OK, IS_KO)
            }

            ///
            ///
            /// # Check if all values are equals to false
            ///
            /// - `b`   The value to check
            ///
            pub fn ko(&mut self, b: bool) -> &mut Unit {
                self.assert(!b, IS_KO, IS_OK)
            }

            ///
            /// # Check if two value are equals
            ///
            /// - `a`       The first value
            /// - `b`       The second value
            ///
            pub fn equals<T: PartialEq>(&mut self, a: T, b: T) -> &mut Unit {
                self.assert(a == b, IS_EQUALS, IS_UNEQUALS)
            }

            ///
            ///
            /// # Check if actual is in min and []ax value
            ///
            ///
            /// - `actual`  The actual value
            /// - `min`     The minimun value for actual
            /// - `max`     The maximum value for actual  
            ///
            pub fn between<T: PartialOrd>(&mut self, actual: T, min: T, max: T) -> &mut Unit {
                self.assert(actual > min && actual < max, IS_BETWEEN, IS_NOT_BETWEEN)
            }

            ///
            ///
            /// Check if values are unequals
            ///  
            /// - `a`   The first value
            /// - `b`   The second value
            ///
            pub fn unequals<T: PartialEq>(&mut self, a: T, b: T) -> &mut Unit {
                self.assert(a != b, IS_UNEQUALS, IS_EQUALS)
            }

            ///
            /// # Check if the value is inferior to the maximum value
            ///
            /// - `actual`      The actual value
            /// - `max`         The maximum value
            ///
            pub fn inferior<T: PartialOrd>(&mut self, actual: T, max: T) -> &mut Unit {
                self.assert(actual < max, IS_INFERIOR, IS_SUPERIOR)
            }

            ///
            /// # Check if the value is superior to the minimun value
            ///
            /// - `actual`      The actual value
            /// - `min`         The minimum value
            ///
            pub fn superior<T: PartialOrd>(&mut self, actual: T, min: T) -> &mut Unit {
                self.assert(actual > min, IS_SUPERIOR, IS_INFERIOR)
            }

            ///
            ///
            /// # Check if a string is not empty
            ///
            /// -  `x` The string to check
            ///
            pub fn not_empty(&mut self, x: &str) -> &mut Unit {
                self.assert(!x.to_string().is_empty(), IS_NOT_EMPTY, IS_EMPTY)
            }

            ///
            ///
            /// # Check if a string contains another string
            ///
            /// -  `x`          The string to check
            /// -  `expected`   The string to verify
            ///
            pub fn contains(&mut self, x: &str, expected: &str) -> &mut Unit {
                self.assert(
                    x.to_string().contains(expected),
                    IS_CONTAINS,
                    IS_NOT_CONTAINS,
                )
            }

            ///
            ///
            /// # Check if a string not contains another string
            ///
            /// -  `x`          The string to check
            /// -  `expected`   The string to verify
            ///
            pub fn not_contains(&mut self, x: &str, expected: &str) -> &mut Unit {
                self.assert(
                    !x.to_string().contains(expected),
                    IS_CONTAINS,
                    IS_NOT_CONTAINS,
                )
            }

            ///
            ///
            /// # Check if a string is empty
            ///
            /// -  `x` The string to check
            ///
            pub fn empty(&mut self, x: &str) -> &mut Unit {
                self.assert(x.to_string().is_empty(), IS_EMPTY, IS_NOT_EMPTY)
            }

            ///
            /// # Check if the given value is a directory
            ///
            /// - `d` The path to check   
            ///
            pub fn is_directory(&mut self, d: &str) -> &mut Unit {
                self.assert(Path::new(d).is_dir(), IS_DIRECTORY, IS_NOT_DIRECTORY)
            }

            ///
            /// # Check if the given value is not a directory
            ///
            /// - `d` The path to check   
            ///
            pub fn is_not_directory(&mut self, d: &str) -> &mut Unit {
                self.assert(!Path::new(d).is_dir(), IS_NOT_DIRECTORY, IS_DIRECTORY)
            }

            ///
            /// # Check if the given value is a file
            ///
            /// - `f` The path to check   
            ///
            pub fn is_file(&mut self, f: &str) -> &mut Unit {
                self.assert(Path::new(f).is_file(), IS_FILE, IS_NOT_FILE)
            }

            ///
            ///
            /// # Chek if a path start with a expected base
            ///
            ///
            /// - `path`    The path to check
            /// - `base`    The path's base
            ///
            ///
            pub fn path_start_with(&mut self, path: &str, base: &str) -> &mut Unit {
                self.assert(
                    Path::new(path).starts_with(base),
                    IS_START_WITH,
                    IS_NOT_START_WITH,
                )
            }

            ///
            ///
            /// # Chek if a path is absolute
            ///
            /// - `path`    The path to check
            ///
            ///
            pub fn path_absolute(&mut self, path: &str) -> &mut Unit {
                self.assert(Path::new(path).is_absolute(), IS_ABSOLUTE, IS_NOT_ABSOLUTE)
            }

            ///
            ///
            /// # Chek if a path is not absolute
            ///
            /// - `path`    The path to check
            ///
            ///
            pub fn path_not_absolute(&mut self, path: &str) -> &mut Unit {
                self.assert(!Path::new(path).is_absolute(), IS_NOT_ABSOLUTE, IS_ABSOLUTE)
            }

            ///
            ///
            /// # Chek if a path exist
            ///
            /// - `path`    The path to check
            ///
            ///
            pub fn path_exists(&mut self, path: &str) -> &mut Unit {
                self.assert(Path::new(path).exists(), IS_EXISTS, IS_NOT_EXISTS)
            }

            ///
            ///
            /// # Chek if a path is not relative
            ///
            /// - `path`    The path to check
            ///
            pub fn path_not_relative(&mut self, path: &str) -> &mut Unit {
                self.assert(!Path::new(path).is_relative(), IS_RELATIVE, IS_NOT_RELATIVE)
            }

            ///
            ///
            /// # Chek if a path is not relative
            ///
            /// - `path`    The path to check
            ///
            pub fn is_executable(&mut self, path: &str) -> &mut Unit {
                self.assert(
                    Path::new(path).is_executable(),
                    IS_EXECUTABLE,
                    IS_NOT_EXECUTABLE,
                )
            }

            ///
            ///
            /// # Chek if a path is relative
            ///
            /// - `path`    The path to check
            ///
            pub fn is_not_executable(&mut self, path: &str) -> &mut Unit {
                self.assert(
                    !Path::new(path).is_executable(),
                    IS_NOT_EXECUTABLE,
                    IS_EXECUTABLE,
                )
            }

            ///
            ///
            /// # Chek if a path is relative
            ///
            /// - `path`    The path to check
            ///
            pub fn path_symlink(&mut self, path: &str) -> &mut Unit {
                self.assert(!Path::new(path).is_symlink(), IS_SYMLINK, IS_NOT_SYMLINK)
            }

            ///
            ///
            /// # Chek if a path exist
            ///
            /// - `path`    The path to check
            ///
            ///
            pub fn path_relative(&mut self, path: &str) -> &mut Unit {
                self.assert(Path::new(path).is_relative(), IS_RELATIVE, IS_NOT_RELATIVE)
            }
            ///
            ///
            /// # Chek if a path is not absolute
            ///
            /// - `path`    The path to check
            ///
            ///
            pub fn path_no_exists(&mut self, path: &str) -> &mut Unit {
                self.assert(!Path::new(path).exists(), IS_NOT_EXISTS, IS_EXISTS)
            }

            ///
            /// # Check if a file contains an another string
            ///
            /// - `file`        The path to check
            /// - `expected`    The expected value
            ///
            ///
            pub fn file_contains(&mut self, file: &str, expected: &str) -> &mut Unit {
                let content = std::fs::read_to_string(file).expect("Failed to parse file");

                self.assert(content.contains(expected), IS_CONTAINS, IS_NOT_CONTAINS)
            }

            ///
            /// # Check if a file no contains an another string
            ///
            /// - `file`        The path to check
            /// - `expected`    The unexpected value
            ///
            ///
            pub fn file_no_contains(&mut self, file: &str, expected: &str) -> &mut Unit {
                let content = std::fs::read_to_string(file).expect("Failed to parse file");
                self.assert(content.contains(expected), IS_NOT_CONTAINS, IS_CONTAINS)
            }
            ///
            /// # Check if two vec length are equals
            ///
            /// - `a`   The first vector
            /// - `b`   The second vector
            ///  
            pub fn vec_length_equals<T: PartialEq>(&mut self, a: Vec<T>, b: Vec<T>) -> &mut Unit {
                self.assert(a.len() == b.len(), IS_EQUALS, IS_UNEQUALS)
            }

            ///
            /// # Check if two vec length are unequals
            ///
            /// - `a`   The first vector
            /// - `b`   The second vector
            ///  
            pub fn vec_length_unequals<T: PartialEq>(&mut self, a: Vec<T>, b: Vec<T>) -> &mut Unit {
                self.assert(a.len() != b.len(), IS_UNEQUALS, IS_EQUALS)
            }

            ///
            /// # Check if a vec contains a value
            ///
            /// - `a`   The vector
            /// - `b`   The value
            ///  
            pub fn vec_contains<T: PartialEq>(&mut self, a: Vec<T>, b: T) -> &mut Unit {
                self.assert(a.contains(&b), IS_CONTAINS, IS_NOT_CONTAINS)
            }

            ///
            /// # Check if a vec not contains a value
            ///
            /// - `a`   The vector
            /// - `b`   The value
            ///  
            pub fn vec_no_contains<T: PartialEq>(&mut self, a: Vec<T>, b: T) -> &mut Unit {
                self.assert(!a.contains(&b), IS_NOT_CONTAINS, IS_CONTAINS)
            }

            ///
            /// # Check if a vec start with a value
            ///
            /// - `a`   The vector
            /// - `b`   The value
            ///  
            pub fn vec_start_with<T: PartialEq>(&mut self, a: Vec<T>, b: T) -> &mut Unit {
                self.assert(a.starts_with(&[b]), IS_START_WITH, IS_NOT_START_WITH)
            }

            ///
            /// # Check if a vec no start with a value
            ///
            /// - `a`   The vector
            /// - `b`   The value
            ///  
            pub fn vec_no_start_with<T: PartialEq>(&mut self, a: Vec<T>, b: T) -> &mut Unit {
                self.assert(!a.starts_with(&[b]), IS_NOT_CONTAINS, IS_CONTAINS)
            }

            ///
            /// # Check if a vec finnish with a value
            ///
            /// - `a`   The vector
            /// - `b`   The value
            ///  
            pub fn vec_end_with<T: PartialEq>(&mut self, a: Vec<T>, b: T) -> &mut Unit {
                self.assert(a.ends_with(&[b]), IS_FINNISH_WITH, IS_NOT_FINNISH_WITH)
            }

            ///
            /// # Check if a vec finnish with a value
            ///
            /// - `a`   The vector
            /// - `b`   The value
            ///  
            pub fn vec_no_end_with<T: PartialEq>(&mut self, a: Vec<T>, b: T) -> &mut Unit {
                self.assert(!a.ends_with(&[b]), IS_NOT_FINNISH_WITH, IS_FINNISH_WITH)
            }

            ///
            /// # Check if a vec is empty
            ///
            /// - `a`   The vector
            ///  
            pub fn vec_empty<T: PartialEq>(&mut self, a: Vec<T>) -> &mut Unit {
                self.assert(a.is_empty(), IS_EMPTY, IS_NOT_EMPTY)
            }

            ///
            /// # Check if a vec is not empty
            ///
            /// - `a`   The vector
            ///  
            pub fn vec_not_empty<T: PartialEq>(&mut self, a: Vec<T>) -> &mut Unit {
                self.assert(!a.is_empty(), IS_NOT_EMPTY, IS_EMPTY)
            }

            //
            /// # Check if the return of the callback is not at this maximum value
            ///
            /// - `callback`        The callback to check
            /// - `max`             The callback maximum value
            ///
            pub fn full(&mut self, callback: fn() -> usize, max: usize) -> &mut Unit {
                self.assert((callback() / max) == 1, IS_FULL, IS_NOT_FULL)
            }

            //
            /// # Check if the return of the callback is not at this maximum value
            ///
            /// - `callback`        The callback to check
            /// - `max`             The callback maximum value
            ///
            pub fn not_full(&mut self, callback: fn() -> usize, max: usize) -> &mut Unit {
                self.assert((callback() / max) < 1, IS_NOT_FULL, IS_FULL)
            }

            ///
            /// # Check if the value is a prime number
            ///
            /// - `x`       The value to check       
            ///
            pub fn prime(&mut self, x: usize) -> &mut Unit {
                self.assert(x % 2 != 0 && x % 3 != 0, IS_NOT_PRIME, IS_PRIME)
            }

            ///
            /// # Check if the value is a pair number
            ///
            /// - `x`       The value to check       
            ///
            pub fn pair(&mut self, x: usize) -> &mut Unit {
                self.assert(x % 2 == 0, IS_PAIR, IS_IMPAIR)
            }

            ///
            /// # Check if the value is an impair number
            ///
            /// - `x`       The value to check       
            ///
            pub fn impair(&mut self, x: usize) -> &mut Unit {
                if x % 2 == 0 {
                    return self.assert(false, IS_PAIR, IS_PAIR);
                }
                if x % 3 == 0 {
                    return self.assert(true, IS_IMPAIR, IS_PAIR);
                }
                return self.assert(false, IS_PRIME, IS_PRIME);
            }
        }

        ///
        /// # Check if all values matches true
        ///  
        /// - `description`     The unit description
        /// - `items`           A vector contening boolean values
        ///
        #[macro_export]
        macro_rules! assert_true {
            ($description:expr,$items:expr) => {
                let mut u = Unit::new($description, NO_PROGRESS, POINT);
                for &item in $items.iter() {
                    u.ok(item);
                }
                u.end().expect("A result not match true");
            };
        }

        ///
        /// # Check if all values matches false
        ///  
        /// - `description`     The unit description
        /// - `items`           A vector contening boolean values
        ///
        #[macro_export]
        macro_rules! assert_false {
            ($description:expr,$items:expr) => {
                let mut u = Unit::new($description, NO_PROGRESS, POINT);
                for &item in $items.iter() {
                    u.ko(item);
                }
                u.end().expect("A result not match false");
            };
        }

        ///
        /// # Check if all directories exist
        ///  
        /// - `description`     The unit description
        /// - `items`           A vector contening all paths
        ///
        #[macro_export]
        macro_rules! assert_directory_exist {
            ($description:expr,$items:expr) => {
                let mut u = Unit::new($description, NO_PROGRESS, POINT);
                for &item in $items.iter() {
                    u.is_directory(item);
                }
                u.end().expect("A directory has not been founded");
            };
        }

        ///
        /// # Check if all files exist
        ///  
        /// - `description`     The unit description
        /// - `items`           A vector contening all paths
        ///
        #[macro_export]
        macro_rules! assert_files_exist {
            ($description:expr,$items:expr) => {
                let mut u = Unit::new($description, NO_PROGRESS, POINT);
                for &item in $items.iter() {
                    u.is_file(item);
                }
                u.end().expect("A file has not been founded");
            };
        }

        ///
        /// # Check if a value contains an another
        ///  
        /// - `description`     The unit description
        /// - `items`           A vector contening all expected values
        /// - `v`               The actual value to check if contains data
        ///
        #[macro_export]
        macro_rules! assert_contains {
            ($description:expr,$items:expr,$v:expr) => {
                let mut u = Unit::new($description, NO_PROGRESS, POINT);
                for &item in $items.iter() {
                    u.contains($v, item);
                }
                u.end().expect("A value has not been founded");
            };
        }

        ///
        /// # Check if a value not contains an another
        ///  
        /// - `description`     The unit description
        /// - `items`           A vector contening all expected values
        /// - `v`               The actual value to check if not contains data
        ///
        #[macro_export]
        macro_rules! assert_not_contains {
            ($description:expr,$items:expr,$v:expr) => {
                let mut u = Unit::new($description, NO_PROGRESS, POINT);
                for &item in $items.iter() {
                    u.not_contains($v, item);
                }
                u.end().expect("A value has not been founded");
            };
        }

        ///
        /// # Check if a value equal to an another
        ///  
        /// - `description`     The unit description
        /// - `items`           A vector contening all values
        /// - `v`               The actual value to check equality
        ///
        #[macro_export]
        macro_rules! assert_equals {
            ($description:expr,$items:expr,$v:expr) => {
                let mut u = Unit::new($description, NO_PROGRESS, POINT);
                for &item in $items.iter() {
                    u.equals($v, item);
                }
                u.end().expect("A value not equal to the expected value");
            };
        }

        ///
        /// # Check if a value not equal to an another
        ///  
        /// - `description`     The unit description
        /// - `items`           A vector contening all values
        /// - `v`               The actual value to check unequality
        ///
        #[macro_export]
        macro_rules! assert_unequals {
            ($description:expr,$items:expr,$v:expr) => {
                let mut u = Unit::new($description, NO_PROGRESS, POINT);
                for &item in $items.iter() {
                    u.unequals($v, item);
                }
                u.end().expect("A value equal to the expected value");
            };
        }

        ///
        /// # Check if a value not equal to an another
        ///  
        /// - `description`     The unit description
        /// - `items`           A vector contening all values
        /// - `v`               The actual value to check unequality
        ///
        #[macro_export]
        macro_rules! unit {
            ($description:expr) => {
                Unit::new($description, NO_PROGRESS, POINT)
            };
        }

        ///
        /// # Check if a value not contains an another
        ///
        /// - `description`     The unit description
        /// - `items`           A vector contening all expected values
        /// - `v`               The actual value to check if not contains data
        ///
        #[macro_export]
        macro_rules! assert_exe {
            ($description:expr,$items:expr) => {
                let mut u = Unit::new($description, NO_PROGRESS, POINT);
                for &item in $items.iter() {
                    u.exe(item);
                }
                u.end().expect("A value is not an executable");
            };
        }
    }
}

#[cfg(test)]
mod tests {

    use crate::{
        assert_contains, assert_directory_exist, assert_equals, assert_false, assert_files_exist,
        assert_not_contains, assert_true, assert_unequals,
        tdd::unit::{Style::POINT, Unit, NO_PROGRESS},
        unit,
    };
    use std::env::consts::OS;
    fn battery_full() -> usize {
        100
    }
    fn battery_not_full() -> usize {
        50
    }

    fn together() -> bool {
        false
    }

    fn pythagore() -> bool {
        4 * 4 + 3 * 3 == 5 * 5
    }

    fn admin(u: &mut Unit) -> &mut Unit {
        u.inferior(1, 2).prime(1).superior(1, 0).between(1, 0, 2)
    }

    fn boolean(u: &mut Unit) -> &mut Unit {
        u.ok(pythagore())
            .ko(together())
            .theory("Check the theorm of pythagore", pythagore)
            .chaos("The bigbang", together)
            .is_directory(".")
            .is_file("README.md")
    }

    fn git_test_install(u: &mut Unit) -> &mut Unit {
        u.exe("/usr/bin/git")
    }

    fn e(u: &mut Unit) -> &mut Unit {
        u.empty("").not_empty(OS)
    }
    fn battery(u: &mut Unit) -> &mut Unit {
        u.full(battery_full, 100).not_full(battery_not_full, 100)
    }
    fn equals(u: &mut Unit) -> &mut Unit {
        u.equals(true, pythagore()).unequals(false, pythagore())
    }

    fn numbers(u: &mut Unit) -> &mut Unit {
        u.prime(1).prime(7).prime(11);
        u.pair(2).pair(4).pair(6);
        u.impair(3).impair(9)
    }

    #[test]
    pub fn unit() {
        unit!("Test the unit framework")
            .describe("Check theories", boolean)
            .describe("Test charge", battery)
            .describe("Check admin users accout number", admin)
            .describe("Test number", numbers)
            .describe("They are equals", equals)
            .describe("Check empty", e)
            .describe("Check if git is installed", git_test_install)
            .end()
            .expect("failed");
    }

    #[test]
    pub fn test_macros() {
        assert_true!("All values must matches true", vec![true, true, true]);
        assert_false!("All values must matches false", vec![false, false, false]);
        assert_directory_exist!(
            "Check if user use linux",
            vec!["/", "/home", "/etc", ".", ".."]
        );
        assert_files_exist!(
            "Check if user use linux",
            vec!["/etc/hosts", "/etc/locale.gen"]
        );

        assert_contains!("Check if user use linux", vec!["linux"], OS);
        assert_not_contains!(
            "Check if user use linux",
            vec!["windows", "ios", "freebsd", "openbsd", "android", "solaris", "netbsd", "macos"],
            OS
        );

        assert_equals!(
            "All value must be equals to linux",
            vec!["linux", "linux", "linux"],
            OS
        );

        assert_unequals!(
            "All os must be only equals to linux",
            vec!["windows", "ios", "freebsd", "openbsd", "android", "solaris", "netbsd", "macos"],
            OS
        );
    }
}