tbpgr_utils 0.0.37 → 0.0.38

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -49,6 +49,7 @@ Or install it yourself as:
49
49
  |[TbpgrUtils Array#together_sample](#arraytogether_sampleor-tsample) |together version of Array#sample. together_sample has alias :tsample |
50
50
  |[TbpgrUtils Array#together_select](#arraytogether_selector-tselect-together_find_all-tfindall) |together version of Enumerable#select. together_select has aliases [:tselect, :together_find_all, :tfindall] |
51
51
  |[TbpgrUtils Array#together_shift](#arraytogether_shift) |together version of Array#shift. together_shift has alias :tshift |
52
+ |[TbpgrUtils Array#together_shuffle](#arraytogether_shuffleor-tshuffle) |together version of Array#shuffle. together_shuffle has alias :tshuffle |
52
53
  |[TbpgrUtils Array#together_with_index](#arraytogether_with_index) |loop all arrays by block with index |
53
54
  |[AttributesHashable.to_hash](#attributeshashableto_hash) |define to_hash method for get instance_values |
54
55
  |[AttributesInitializable::ClassMethods.attr_accessor_init](#attributesinitializableclassmethodsattr_accessor_init) |generate attr_accessor + initializer |
@@ -348,44 +349,56 @@ together_include? has alias :tinclude?
348
349
 
349
350
  both include single ret case
350
351
  ~~~ruby
351
- lists = [[*1..5], [*5..9]]
352
- ret = lists.together_include? 5
353
- print ret # => true
352
+ require 'tbpgr_utils'
353
+
354
+ lists = [[*1..5], [*5..9]]
355
+ ret = lists.together_include? 5
356
+ print ret # => true
354
357
  ~~~
355
358
 
356
359
  one include single ret case
357
360
  ~~~ruby
358
- lists = [[*1..5], [*5..9]]
359
- ret = lists.together_include? 9
360
- print ret # => true
361
+ require 'tbpgr_utils'
362
+
363
+ lists = [[*1..5], [*5..9]]
364
+ ret = lists.together_include? 9
365
+ print ret # => true
361
366
  ~~~
362
367
 
363
368
  both not include single ret case
364
369
  ~~~ruby
365
- lists = [[*1..5], [*5..9]]
366
- ret = lists.together_include? 10
367
- print ret # => false
370
+ require 'tbpgr_utils'
371
+
372
+ lists = [[*1..5], [*5..9]]
373
+ ret = lists.together_include? 10
374
+ print ret # => false
368
375
  ~~~
369
376
 
370
377
  both include multi ret case
371
378
  ~~~ruby
372
- lists = [[*1..5], [*5..9]]
373
- ret = lists.together_include? 5, true
374
- print ret # => [true, true]
379
+ require 'tbpgr_utils'
380
+
381
+ lists = [[*1..5], [*5..9]]
382
+ ret = lists.together_include? 5, true
383
+ print ret # => [true, true]
375
384
  ~~~
376
385
 
377
386
  one include multi ret case
378
387
  ~~~ruby
379
- lists = [[*1..5], [*5..9]]
380
- ret = lists.together_include? 9, true
381
- print ret # => [false, true]
388
+ require 'tbpgr_utils'
389
+
390
+ lists = [[*1..5], [*5..9]]
391
+ ret = lists.together_include? 9, true
392
+ print ret # => [false, true]
382
393
  ~~~
383
394
 
384
395
  both not include multi ret case
385
396
  ~~~ruby
386
- lists = [[*1..5], [*5..9]]
387
- ret = lists.together_include? 10, true
388
- print ret # => [false, false]
397
+ require 'tbpgr_utils'
398
+
399
+ lists = [[*1..5], [*5..9]]
400
+ ret = lists.together_include? 10, true
401
+ print ret # => [false, false]
389
402
  ~~~
390
403
 
391
404
  [back to list](#list)
@@ -395,6 +408,8 @@ together_index has alias :tindex
395
408
 
396
409
  both index exist case
397
410
  ~~~ruby
411
+ require 'tbpgr_utils'
412
+
398
413
  lists = [[*1..5], [*5..9]]
399
414
  ret = lists.together_index 5
400
415
  print ret # => [4, 0]
@@ -402,6 +417,8 @@ print ret # => [4, 0]
402
417
 
403
418
  one include single ret case
404
419
  ~~~ruby
420
+ require 'tbpgr_utils'
421
+
405
422
  lists = [[*1..5], [*5..9]]
406
423
  ret = lists.together_index 4
407
424
  print ret # => [3, nil]
@@ -409,6 +426,8 @@ print ret # => [3, nil]
409
426
 
410
427
  both not include single ret case
411
428
  ~~~ruby
429
+ require 'tbpgr_utils'
430
+
412
431
  lists = [[*1..5], [*5..9]]
413
432
  ret = lists.together_index 10
414
433
  print ret # => [nil, nil]
@@ -421,6 +440,8 @@ together_insert has alias :tinsert
421
440
 
422
441
  both insert exist case
423
442
  ~~~ruby
443
+ require 'tbpgr_utils'
444
+
424
445
  lists = [[*1..5], [*5..9]]
425
446
  ret = lists.together_insert(1, 55, 66)
426
447
  print ret # => [[1, 55, 66, 2, 3, 4, 5], [5, 55, 66, 6, 7, 8, 9]]
@@ -428,6 +449,8 @@ print ret # => [[1, 55, 66, 2, 3, 4, 5], [5, 55, 66, 6, 7, 8, 9]]
428
449
 
429
450
  both insert exist and minus index case
430
451
  ~~~ruby
452
+ require 'tbpgr_utils'
453
+
431
454
  lists = [[*1..5], [*5..9]]
432
455
  ret = lists.together_insert(-2, 55, 66)
433
456
  print ret # => [[1, 2, 3, 4, 55, 66, 5], [5, 6, 7, 8, 55, 66, 9]]
@@ -435,6 +458,8 @@ print ret # => [[1, 2, 3, 4, 55, 66, 5], [5, 6, 7, 8, 55, 66, 9]]
435
458
 
436
459
  both insert exist case
437
460
  ~~~ruby
461
+ require 'tbpgr_utils'
462
+
438
463
  lists = [[*1..5], [*5..9]]
439
464
  ret = lists.together_insert(6, 55, 66)
440
465
  print ret # => [[1, 2, 3, 4, 5, nil, 55, 66], [5, 6, 7, 8, 9, nil, 55, 66]],
@@ -447,6 +472,8 @@ together_last has alias :tlast
447
472
 
448
473
  no args case
449
474
  ~~~ruby
475
+ require 'tbpgr_utils'
476
+
450
477
  lists = [[*1..5], [*6..10]]
451
478
  ret = lists.together_last
452
479
  print ret # => [5, 10]
@@ -454,6 +481,8 @@ print ret # => [5, 10]
454
481
 
455
482
  has args 2 case
456
483
  ~~~ruby
484
+ require 'tbpgr_utils'
485
+
457
486
  lists = [[*1..5], [*6..10]]
458
487
  ret = lists.together_last 2
459
488
  print ret # => [[4, 5], [9, 10]]
@@ -461,6 +490,8 @@ print ret # => [[4, 5], [9, 10]]
461
490
 
462
491
  has args 0 case
463
492
  ~~~ruby
493
+ require 'tbpgr_utils'
494
+
464
495
  lists = [[*1..5], [*6..10]]
465
496
  ret = lists.together_last 0
466
497
  print ret # => [[], []]
@@ -468,6 +499,8 @@ print ret # => [[], []]
468
499
 
469
500
  has args over size case
470
501
  ~~~ruby
502
+ require 'tbpgr_utils'
503
+
471
504
  lists = [[*1..5], [*6..10]]
472
505
  ret = lists.together_last 6
473
506
  print ret # => [[*1..5], [*6..10]]
@@ -533,6 +566,8 @@ together_pop has alias :tpop
533
566
 
534
567
  not empty case
535
568
  ~~~ruby
569
+ require 'tbpgr_utils'
570
+
536
571
  lists = [[1, 2], [5, 6]]
537
572
  ret = lists.together_pop
538
573
  print ret # => [2, 6]
@@ -541,6 +576,8 @@ print lists # => [1, 5]
541
576
 
542
577
  empty case
543
578
  ~~~ruby
579
+ require 'tbpgr_utils'
580
+
544
581
  lists = [[], []]
545
582
  ret = lists.together_pop
546
583
  print ret # => [nil, nil]
@@ -548,6 +585,9 @@ print lists # => [[], []]
548
585
  ~~~
549
586
 
550
587
  not empty case with args
588
+ ~~~ruby
589
+ require 'tbpgr_utils'
590
+
551
591
  lists = [[1, 2], [5, 6]]
552
592
  ret = lists.together_pop 2
553
593
  print ret # => [[1, 2], [5, 6]]
@@ -555,6 +595,9 @@ print lists # => [[], []]
555
595
  ~~~
556
596
 
557
597
  not empty case with args
598
+ ~~~ruby
599
+ require 'tbpgr_utils'
600
+
558
601
  lists = [[], []]
559
602
  ret = lists.together_pop 2
560
603
  print ret # => [[], []]
@@ -567,6 +610,8 @@ print lists # => [[], []]
567
610
  * if you want to single return
568
611
 
569
612
  ~~~ruby
613
+ require 'tbpgr_utils'
614
+
570
615
  firsts = [1, 2, 3, 4]
571
616
  seconds = [4, 2, 3, 1]
572
617
  ret = [firsts, seconds].together_reduce{|memo, first, second|memo + first + second}
@@ -576,6 +621,8 @@ print ret # => output 20
576
621
  * if you want to single return with init value
577
622
 
578
623
  ~~~ruby
624
+ require 'tbpgr_utils'
625
+
579
626
  firsts = [1, 2, 3, 4]
580
627
  seconds = [4, 2, 3, 1]
581
628
  ret = [firsts, seconds].together_reduce(10){|memo, first, second|memo + first + second}
@@ -585,6 +632,8 @@ print ret # => output 30
585
632
  * if you want to single return with init string value
586
633
 
587
634
  ~~~ruby
635
+ require 'tbpgr_utils'
636
+
588
637
  firsts = %w{a b c}
589
638
  seconds = %w{1 2 3}
590
639
  ret = [firsts, seconds].together_reduce('start-'){|memo, first, second|memo + first + second}
@@ -594,6 +643,8 @@ print ret # => output 'start-a1b2c3'
594
643
  * if you want to single return with init Array value
595
644
 
596
645
  ~~~ruby
646
+ require 'tbpgr_utils'
647
+
597
648
  firsts = [1, 2, 3, 4]
598
649
  seconds = [4, 2, 3, 1]
599
650
  ret = [firsts, seconds].together_reduce([]){|memo, first, second|memo << first + second}
@@ -603,6 +654,8 @@ print ret # => output [5, 4, 6, 5]
603
654
  * if you want to single return with init Hash value
604
655
 
605
656
  ~~~ruby
657
+ require 'tbpgr_utils'
658
+
606
659
  firsts = [1, 2, 3, 4]
607
660
  seconds = [4, 2, 3, 1]
608
661
  ret = [firsts, seconds].together_reduce({}){|memo, first, second|memo[first] = second;memo}
@@ -616,6 +669,8 @@ together_reverse has alias :treverse
616
669
 
617
670
  not empty case
618
671
  ~~~ruby
672
+ require 'tbpgr_utils'
673
+
619
674
  lists = [[1, 2], [5, 6]]
620
675
  ret = lists.together_reverse
621
676
  print ret # => [[2, 1], [6, 5]]
@@ -624,6 +679,8 @@ print lists # => [[1, 2], [5, 6]]
624
679
 
625
680
  one empty case
626
681
  ~~~ruby
682
+ require 'tbpgr_utils'
683
+
627
684
  lists = [[1, 2], []]
628
685
  ret = lists.together_reverse
629
686
  print ret # => [[2, 1], []]
@@ -637,6 +694,8 @@ together_reverse! has alias :treverse!
637
694
 
638
695
  not empty case
639
696
  ~~~ruby
697
+ require 'tbpgr_utils'
698
+
640
699
  lists = [[1, 2], [5, 6]]
641
700
  ret = lists.together_reverse!
642
701
  print ret # => [[2, 1], [6, 5]]
@@ -645,6 +704,8 @@ print lists # => [[2, 1], [6, 5]]
645
704
 
646
705
  one empty case
647
706
  ~~~ruby
707
+ require 'tbpgr_utils'
708
+
648
709
  lists = [[1, 2], []]
649
710
  ret = lists.together_reverse!
650
711
  print ret # => [[2, 1], []]
@@ -658,6 +719,8 @@ together_sample has alias :tsample
658
719
 
659
720
  not empty case
660
721
  ~~~ruby
722
+ require 'tbpgr_utils'
723
+
661
724
  lists = [[1, 2], [5, 6]]
662
725
  ret = lists.together_sample
663
726
  print ret # => [1 or 2, 5 or 6]
@@ -665,24 +728,35 @@ print ret # => [1 or 2, 5 or 6]
665
728
 
666
729
  empty case
667
730
  ~~~ruby
731
+ require 'tbpgr_utils'
732
+
668
733
  lists = [[], []]
669
734
  ret = lists.together_sample
670
735
  print ret # => [nil, nil]
671
736
  ~~~
672
737
 
673
738
  not empty case with args
739
+ ~~~ruby
740
+ require 'tbpgr_utils'
741
+
674
742
  lists = [[1, 2], [5, 6]]
675
743
  ret = lists.together_sample 2
676
744
  print ret # => [[1 or 2, 1 or 2], [5 or 6, 5 or 6]]
677
745
  ~~~
678
746
 
679
747
  not empty case with args
748
+ ~~~ruby
749
+ require 'tbpgr_utils'
750
+
680
751
  lists = [[], []]
681
752
  ret = lists.together_sample 2
682
753
  print ret # => [[], []]
683
754
  ~~~
684
755
 
685
756
  not empty, over size case with args
757
+ ~~~ruby
758
+ require 'tbpgr_utils'
759
+
686
760
  lists = [[1, 2], [5, 6]]
687
761
  ret = lists.together_sample 3
688
762
  print ret # => [[1 or 2, 1 or 2], [5 or 6, 5 or 6]]
@@ -717,6 +791,8 @@ together_shift has alias :tshift
717
791
 
718
792
  not empty case
719
793
  ~~~ruby
794
+ require 'tbpgr_utils'
795
+
720
796
  lists = [[1, 2], [5, 6]]
721
797
  ret = lists.together_shift
722
798
  print ret # => [1, 5]
@@ -725,6 +801,8 @@ print lists # => [2, 6]
725
801
 
726
802
  empty case
727
803
  ~~~ruby
804
+ require 'tbpgr_utils'
805
+
728
806
  lists = [[], []]
729
807
  ret = lists.together_shift
730
808
  print ret # => [nil, nil]
@@ -732,7 +810,9 @@ print lists # => [[], []]
732
810
  ~~~
733
811
 
734
812
  not empty case
735
- ~~~ruby with args
813
+ ~~~ruby
814
+ require 'tbpgr_utils'
815
+
736
816
  lists = [[1, 2], [5, 6]]
737
817
  ret = lists.together_shift 2
738
818
  print ret # => [[1, 2], [5, 6]]
@@ -740,7 +820,9 @@ print lists # => [[], []]
740
820
  ~~~
741
821
 
742
822
  not empty case
743
- ~~~ruby with args
823
+ ~~~ruby
824
+ require 'tbpgr_utils'
825
+
744
826
  lists = [[], []]
745
827
  ret = lists.together_shift 2
746
828
  print ret # => [[], []]
@@ -749,6 +831,19 @@ print lists # => [[], []]
749
831
 
750
832
  [back to list](#list)
751
833
 
834
+ ### Array#together_shuffle(or :tshuffle)
835
+ together_shuffle has alias :tshuffle
836
+
837
+ ~~~ruby
838
+ require 'tbpgr_utils'
839
+
840
+ lists = [[1, 2], [5, 6]]
841
+ ret = lists.together_shuffle
842
+ print ret # => [[1 or 2, 1 or 2], [5 or 6, 5 or 6]]
843
+ ~~~
844
+
845
+ [back to list](#list)
846
+
752
847
  ### Array#together_with_index
753
848
  ~~~ruby
754
849
  require 'tbpgr_utils'
@@ -1369,6 +1464,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
1369
1464
  https://github.com/tbpgr/tbpgr_utils_snippets
1370
1465
 
1371
1466
  ## History
1467
+ * version 0.0.38 : add Array#together_shuffle(alias tshuffle).
1372
1468
  * version 0.0.37 : add Array#together_sample(alias tsample).
1373
1469
  * version 0.0.36 : add Array#together_reverse,Array#together_reverse!(alias treverse, alias treverse!).
1374
1470
  * version 0.0.35 : add Array#together_pop(alias tpop).
@@ -1,49 +1,49 @@
1
- # encoding: utf-8
2
- require 'open_classes/object'
3
- require 'open_classes/module'
4
- require 'open_classes/array/together_helper'
5
-
6
- # Array
7
- class Array
8
- include TogetherHelper
9
-
10
- # Arrays bulk sample.
11
- #
12
- # together_sample has alias :tsample
13
- #
14
- # not empty case
15
- # lists = [[1, 2], [5, 6]]
16
- # ret = lists.together_sample
17
- # print ret # => [1 or 2, 5 or 6]
18
- #
19
- # empty case
20
- # lists = [[], []]
21
- # ret = lists.together_sample
22
- # print ret # => [nil, nil]
23
- #
24
- # not empty case with args
25
- # lists = [[1, 2], [5, 6]]
26
- # ret = lists.together_sample 2
27
- # print ret # => [[1 or 2, 1 or 2], [5 or 6, 5 or 6]]
28
- #
29
- # not empty case with args
30
- # lists = [[], []]
31
- # ret = lists.together_sample 2
32
- # print ret # => [[], []]
33
- #
34
- # not empty, over size case with args
35
- # lists = [[1, 2], [5, 6]]
36
- # ret = lists.together_sample 3
37
- # print ret # => [[1 or 2, 1 or 2], [5 or 6, 5 or 6]]
38
- #
39
- def together_sample(count = nil)
40
- if_not_contain_array_rails_type_error
41
- if count.nil?
42
- reduce([]) { |ret, list|ret << list.sample }
43
- else
44
- reduce([]) { |ret, list|ret << list.sample(count) }
45
- end
46
- end
47
-
48
- alias_method :tsample, :together_sample
49
- end
1
+ # encoding: utf-8
2
+ require 'open_classes/object'
3
+ require 'open_classes/module'
4
+ require 'open_classes/array/together_helper'
5
+
6
+ # Array
7
+ class Array
8
+ include TogetherHelper
9
+
10
+ # Arrays bulk sample.
11
+ #
12
+ # together_sample has alias :tsample
13
+ #
14
+ # not empty case
15
+ # lists = [[1, 2], [5, 6]]
16
+ # ret = lists.together_sample
17
+ # print ret # => [1 or 2, 5 or 6]
18
+ #
19
+ # empty case
20
+ # lists = [[], []]
21
+ # ret = lists.together_sample
22
+ # print ret # => [nil, nil]
23
+ #
24
+ # not empty case with args
25
+ # lists = [[1, 2], [5, 6]]
26
+ # ret = lists.together_sample 2
27
+ # print ret # => [[1 or 2, 1 or 2], [5 or 6, 5 or 6]]
28
+ #
29
+ # not empty case with args
30
+ # lists = [[], []]
31
+ # ret = lists.together_sample 2
32
+ # print ret # => [[], []]
33
+ #
34
+ # not empty, over size case with args
35
+ # lists = [[1, 2], [5, 6]]
36
+ # ret = lists.together_sample 3
37
+ # print ret # => [[1 or 2, 1 or 2], [5 or 6, 5 or 6]]
38
+ #
39
+ def together_sample(count = nil)
40
+ if_not_contain_array_rails_type_error
41
+ if count.nil?
42
+ reduce([]) { |ret, list|ret << list.sample }
43
+ else
44
+ reduce([]) { |ret, list|ret << list.sample(count) }
45
+ end
46
+ end
47
+
48
+ alias_method :tsample, :together_sample
49
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ require 'open_classes/object'
3
+ require 'open_classes/module'
4
+ require 'open_classes/array/together_helper'
5
+
6
+ # Array
7
+ class Array
8
+ include TogetherHelper
9
+
10
+ # Arrays bulk shuffle.
11
+ #
12
+ # together_shuffle has alias :tshuffle
13
+ #
14
+ # lists = [[1, 2], [5, 6]]
15
+ # ret = lists.together_shuffle
16
+ # print ret # => [[1 or 2, 1 or 2], [5 or 6, 5 or 6]]
17
+ def together_shuffle(count = nil)
18
+ if_not_contain_array_rails_type_error
19
+ reduce([]) { |ret, list|ret << list.shuffle }
20
+ end
21
+
22
+ alias_method :tshuffle, :together_shuffle
23
+ end
@@ -21,4 +21,5 @@ require 'open_classes/array/together_reverse'
21
21
  require 'open_classes/array/together_sample'
22
22
  require 'open_classes/array/together_select'
23
23
  require 'open_classes/array/together_shift'
24
+ require 'open_classes/array/together_shuffle'
24
25
  require 'open_classes/array/together_with_index'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.37'
5
+ VERSION = '0.0.38'
6
6
  end
@@ -1,122 +1,122 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require "active_support/core_ext/object/inclusion"
4
- require 'tbpgr_utils'
5
-
6
- describe Array do
7
- context :together_sample do
8
- cases = [
9
- {
10
- case_no: 1,
11
- case_title: 'not empty case',
12
- inputs: [[1, 2], [5, 6]],
13
- method_name: 'together_sample',
14
- expected_first: "actual[0].in? [1, 2]",
15
- expected_second: "actual[1].in? [5, 6]",
16
- },
17
- {
18
- case_no: 2,
19
- case_title: 'one empty case',
20
- inputs: [[1, 2], []],
21
- method_name: 'together_sample',
22
- expected_first: "actual[0].in? [1, 2]",
23
- expected_second: "actual[1].nil?",
24
- },
25
- {
26
- case_no: 3,
27
- case_title: 'both empty case',
28
- inputs: [[], []],
29
- method_name: 'together_sample',
30
- expected_first: "actual[0].nil?",
31
- expected_second: "actual[1].nil?",
32
- },
33
- {
34
- case_no: 4,
35
- case_title: 'not empty, has args case',
36
- inputs: [[1, 2], [5, 6]],
37
- method_name: 'together_sample',
38
- args: 2,
39
- expected_size: 2,
40
- expected_first: "f.in? [1, 2]",
41
- expected_second: "s.in? [5, 6]",
42
- has_args: true,
43
- },
44
- {
45
- case_no: 5,
46
- case_title: 'both empty, has args case',
47
- inputs: [[], []],
48
- method_name: 'together_sample',
49
- args: 2,
50
- expected_size: 0,
51
- expected_ret: [[], []],
52
- expected_self: [[], []],
53
- has_args: true,
54
- },
55
- {
56
- case_no: 6,
57
- case_title: 'not empty, over size, has args case',
58
- inputs: [[1, 2], [5, 6]],
59
- method_name: 'together_sample',
60
- args: 3,
61
- expected_size: 2,
62
- expected_first: "f.in? [1, 2]",
63
- expected_second: "s.in? [5, 6]",
64
- has_args: true,
65
- },
66
- {
67
- case_no: 7,
68
- case_title: 'not empty case',
69
- inputs: [[1, 2], [5, 6]],
70
- method_name: 'tsample',
71
- expected_first: "actual[0].in? [1, 2]",
72
- expected_second: "actual[1].in? [5, 6]",
73
- },
74
- ]
75
-
76
- cases.each do |c|
77
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
78
- begin
79
- case_before c
80
-
81
- # -- given --
82
- # nothing
83
-
84
- # -- when --
85
- if c[:has_args]
86
- actual = c[:inputs].send c[:method_name], c[:args]
87
- # -- then --
88
- actual[0].each do |f|
89
- first_ret = eval c[:expected_first], binding
90
- expect(first_ret).to be_true
91
- end
92
- expect(actual[0].size).to eq(c[:expected_size])
93
-
94
- actual[1].each do |s|
95
- second_ret = eval c[:expected_second], binding
96
- expect(second_ret).to be_true
97
- end
98
- expect(actual[1].size).to eq(c[:expected_size])
99
- else
100
- actual = c[:inputs].send c[:method_name]
101
- # -- then --
102
- first_ret = eval c[:expected_first], binding
103
- expect(first_ret).to be_true
104
- second_ret = eval c[:expected_second], binding
105
- expect(second_ret).to be_true
106
- end
107
-
108
- ensure
109
- case_after c
110
- end
111
- end
112
-
113
- def case_before(c)
114
- # implement each case before
115
- end
116
-
117
- def case_after(c)
118
- # implement each case after
119
- end
120
- end
121
- end
122
- end
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'active_support/core_ext/object/inclusion'
4
+ require 'tbpgr_utils'
5
+
6
+ describe Array do
7
+ context :together_sample do
8
+ cases = [
9
+ {
10
+ case_no: 1,
11
+ case_title: 'not empty case',
12
+ inputs: [[1, 2], [5, 6]],
13
+ method_name: 'together_sample',
14
+ expected_first: 'actual[0].in? [1, 2]',
15
+ expected_second: 'actual[1].in? [5, 6]',
16
+ },
17
+ {
18
+ case_no: 2,
19
+ case_title: 'one empty case',
20
+ inputs: [[1, 2], []],
21
+ method_name: 'together_sample',
22
+ expected_first: 'actual[0].in? [1, 2]',
23
+ expected_second: 'actual[1].nil?',
24
+ },
25
+ {
26
+ case_no: 3,
27
+ case_title: 'both empty case',
28
+ inputs: [[], []],
29
+ method_name: 'together_sample',
30
+ expected_first: 'actual[0].nil?',
31
+ expected_second: 'actual[1].nil?',
32
+ },
33
+ {
34
+ case_no: 4,
35
+ case_title: 'not empty, has args case',
36
+ inputs: [[1, 2], [5, 6]],
37
+ method_name: 'together_sample',
38
+ args: 2,
39
+ expected_size: 2,
40
+ expected_first: 'f.in? [1, 2]',
41
+ expected_second: 's.in? [5, 6]',
42
+ has_args: true,
43
+ },
44
+ {
45
+ case_no: 5,
46
+ case_title: 'both empty, has args case',
47
+ inputs: [[], []],
48
+ method_name: 'together_sample',
49
+ args: 2,
50
+ expected_size: 0,
51
+ expected_ret: [[], []],
52
+ expected_self: [[], []],
53
+ has_args: true,
54
+ },
55
+ {
56
+ case_no: 6,
57
+ case_title: 'not empty, over size, has args case',
58
+ inputs: [[1, 2], [5, 6]],
59
+ method_name: 'together_sample',
60
+ args: 3,
61
+ expected_size: 2,
62
+ expected_first: 'f.in? [1, 2]',
63
+ expected_second: 's.in? [5, 6]',
64
+ has_args: true,
65
+ },
66
+ {
67
+ case_no: 7,
68
+ case_title: 'not empty case',
69
+ inputs: [[1, 2], [5, 6]],
70
+ method_name: 'tsample',
71
+ expected_first: 'actual[0].in? [1, 2]',
72
+ expected_second: 'actual[1].in? [5, 6]',
73
+ },
74
+ ]
75
+
76
+ cases.each do |c|
77
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
78
+ begin
79
+ case_before c
80
+
81
+ # -- given --
82
+ # nothing
83
+
84
+ # -- when --
85
+ if c[:has_args]
86
+ actual = c[:inputs].send c[:method_name], c[:args]
87
+ # -- then --
88
+ actual[0].each do |f|
89
+ first_ret = eval c[:expected_first], binding
90
+ expect(first_ret).to be_true
91
+ end
92
+ expect(actual[0].size).to eq(c[:expected_size])
93
+
94
+ actual[1].each do |s|
95
+ second_ret = eval c[:expected_second], binding
96
+ expect(second_ret).to be_true
97
+ end
98
+ expect(actual[1].size).to eq(c[:expected_size])
99
+ else
100
+ actual = c[:inputs].send c[:method_name]
101
+ # -- then --
102
+ first_ret = eval c[:expected_first], binding
103
+ expect(first_ret).to be_true
104
+ second_ret = eval c[:expected_second], binding
105
+ expect(second_ret).to be_true
106
+ end
107
+
108
+ ensure
109
+ case_after c
110
+ end
111
+ end
112
+
113
+ def case_before(c)
114
+ # implement each case before
115
+ end
116
+
117
+ def case_after(c)
118
+ # implement each case after
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'active_support/core_ext/object/inclusion'
4
+ require 'tbpgr_utils'
5
+
6
+ describe Array do
7
+ context :together_shuffle do
8
+ cases = [
9
+ {
10
+ case_no: 1,
11
+ case_title: 'not empty case',
12
+ inputs: [[1, 2], [5, 6]],
13
+ method_name: 'together_shuffle',
14
+ expected_first: 'actual[0].sort == c[:inputs][0]',
15
+ expected_second: 'actual[1].sort == c[:inputs][1]',
16
+ },
17
+ {
18
+ case_no: 2,
19
+ case_title: 'not empty case',
20
+ inputs: [[1, 2], [5, 6]],
21
+ method_name: 'tshuffle',
22
+ expected_first: 'actual[0].sort == c[:inputs][0]',
23
+ expected_second: 'actual[1].sort == c[:inputs][1]',
24
+ },
25
+ ]
26
+
27
+ cases.each do |c|
28
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
29
+ begin
30
+ case_before c
31
+
32
+ # -- given --
33
+ # nothing
34
+
35
+ # -- when --
36
+ actual = c[:inputs].send c[:method_name]
37
+
38
+ # -- then --
39
+ expect(actual[0].sort).to eq(c[:inputs][0])
40
+ expect(actual[1].sort).to eq(c[:inputs][1])
41
+ ensure
42
+ case_after c
43
+ end
44
+ end
45
+
46
+ def case_before(c)
47
+ # implement each case before
48
+ end
49
+
50
+ def case_after(c)
51
+ # implement each case after
52
+ end
53
+ end
54
+ end
55
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tbpgr_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.37
4
+ version: 0.0.38
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-13 00:00:00.000000000 Z
12
+ date: 2014-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &21931512 !ruby/object:Gem::Requirement
16
+ requirement: &26179104 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 4.0.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *21931512
24
+ version_requirements: *26179104
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &21931224 !ruby/object:Gem::Requirement
27
+ requirement: &26178816 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.3'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *21931224
35
+ version_requirements: *26178816
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &21930996 !ruby/object:Gem::Requirement
38
+ requirement: &26178588 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *21930996
46
+ version_requirements: *26178588
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &21930672 !ruby/object:Gem::Requirement
49
+ requirement: &26178264 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.14.1
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *21930672
57
+ version_requirements: *26178264
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &21930372 !ruby/object:Gem::Requirement
60
+ requirement: &26177964 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.8.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *21930372
68
+ version_requirements: *26177964
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -109,6 +109,7 @@ files:
109
109
  - lib/open_classes/array/together_sample.rb
110
110
  - lib/open_classes/array/together_select.rb
111
111
  - lib/open_classes/array/together_shift.rb
112
+ - lib/open_classes/array/together_shuffle.rb
112
113
  - lib/open_classes/array/together_with_index.rb
113
114
  - lib/open_classes/file.rb
114
115
  - lib/open_classes/kernel.rb
@@ -143,8 +144,10 @@ files:
143
144
  - spec/open_classes/array/together_pop_spec.rb
144
145
  - spec/open_classes/array/together_reduce_spec.rb
145
146
  - spec/open_classes/array/together_reverse_spec.rb
147
+ - spec/open_classes/array/together_sample_spec.rb
146
148
  - spec/open_classes/array/together_select_spec.rb
147
149
  - spec/open_classes/array/together_shift_spec.rb
150
+ - spec/open_classes/array/together_shuffle_spec.rb
148
151
  - spec/open_classes/array/together_spec.rb
149
152
  - spec/open_classes/array/together_with_index_spec.rb
150
153
  - spec/open_classes/file_spec.rb
@@ -152,7 +155,6 @@ files:
152
155
  - spec/open_classes/module_spec.rb
153
156
  - spec/open_classes/object_spec.rb
154
157
  - spec/open_classes/string_spec.rb
155
- - spec/open_classes/together_sample_spec.rb
156
158
  - spec/spec_helper.rb
157
159
  - spec/templatable_spec.rb
158
160
  - spec/template_methodable_spec.rb
@@ -205,8 +207,10 @@ test_files:
205
207
  - spec/open_classes/array/together_pop_spec.rb
206
208
  - spec/open_classes/array/together_reduce_spec.rb
207
209
  - spec/open_classes/array/together_reverse_spec.rb
210
+ - spec/open_classes/array/together_sample_spec.rb
208
211
  - spec/open_classes/array/together_select_spec.rb
209
212
  - spec/open_classes/array/together_shift_spec.rb
213
+ - spec/open_classes/array/together_shuffle_spec.rb
210
214
  - spec/open_classes/array/together_spec.rb
211
215
  - spec/open_classes/array/together_with_index_spec.rb
212
216
  - spec/open_classes/file_spec.rb
@@ -214,7 +218,6 @@ test_files:
214
218
  - spec/open_classes/module_spec.rb
215
219
  - spec/open_classes/object_spec.rb
216
220
  - spec/open_classes/string_spec.rb
217
- - spec/open_classes/together_sample_spec.rb
218
221
  - spec/spec_helper.rb
219
222
  - spec/templatable_spec.rb
220
223
  - spec/template_methodable_spec.rb