1
1
import { describe , expect , it } from '@jest/globals' ;
2
2
import {
3
- divisors ,
4
3
abundance ,
4
+ divisors ,
5
+ isPrime ,
5
6
nextPrimeFactor ,
6
7
primeFactors ,
8
+ properDivisors ,
7
9
___DIVISORS_DEFICIENT___ ,
8
10
___DIVISORS_PERFECT___ ,
9
11
___DIVISORS_ABUNDANT___
10
12
} from './divisors.js' ;
11
13
12
- describe ( 'divisors of a number ' , ( ) => {
14
+ describe ( 'divisors and prime numbers ' , ( ) => {
13
15
it ( 'divisors of one' , ( ) => {
14
16
expect . assertions ( 1 ) ;
15
17
@@ -35,6 +37,16 @@ describe('divisors of a number', () => {
35
37
] ) ;
36
38
} ) ;
37
39
40
+ it ( 'proper divisors of a number' , ( ) => {
41
+ expect . assertions ( 5 ) ;
42
+
43
+ expect ( properDivisors ( 1 ) ) . toStrictEqual ( [ ] ) ;
44
+ expect ( properDivisors ( 2 ) ) . toStrictEqual ( [ 1 ] ) ;
45
+ expect ( properDivisors ( 8 ) ) . toStrictEqual ( [ 1 , 2 , 4 ] ) ;
46
+ expect ( properDivisors ( 9 ) ) . toStrictEqual ( [ 1 , 3 ] ) ;
47
+ expect ( properDivisors ( 16 ) ) . toStrictEqual ( [ 1 , 2 , 4 , 8 ] ) ;
48
+ } ) ;
49
+
38
50
it ( 'next prime factor of a target number' , ( ) => {
39
51
expect . assertions ( 5 ) ;
40
52
@@ -81,6 +93,24 @@ describe('divisors of a number', () => {
81
93
} ) ;
82
94
} ) ;
83
95
96
+ it ( 'some numbers are prime' , ( ) => {
97
+ expect . assertions ( 4 ) ;
98
+
99
+ expect ( isPrime ( 1 ) ) . toBe ( false ) ;
100
+ expect ( isPrime ( 2 ) ) . toBe ( true ) ;
101
+ expect ( isPrime ( 7 ) ) . toBe ( true ) ;
102
+ expect ( isPrime ( 13 ) ) . toBe ( true ) ;
103
+ } ) ;
104
+
105
+ it ( 'some numbers are not prime' , ( ) => {
106
+ expect . assertions ( 4 ) ;
107
+
108
+ expect ( isPrime ( 4 ) ) . toBe ( false ) ;
109
+ expect ( isPrime ( 10 ) ) . toBe ( false ) ;
110
+ expect ( isPrime ( 100 ) ) . toBe ( false ) ;
111
+ expect ( isPrime ( 3000 ) ) . toBe ( false ) ;
112
+ } ) ;
113
+
84
114
it ( 'abundance of a integer number' , ( ) => {
85
115
expect . assertions ( 3 ) ;
86
116
0 commit comments