Skip to content

Commit b53c860

Browse files
authored
Update tests rational numbers (#2725)
* Sync test.toml * Update test file * Update proof solution
1 parent c4e4ed8 commit b53c860

File tree

4 files changed

+110
-45
lines changed

4 files changed

+110
-45
lines changed

exercises/practice/rational-numbers/.meta/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
],
55
"contributors": [
66
"ankorGH",
7+
"jagdish-15",
78
"SleeplessByte",
89
"tejasbubane"
910
],

exercises/practice/rational-numbers/.meta/proof.ci.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ class Rational {
4040
return new Rational(Math.abs(this.numerator), Math.abs(this.denominator));
4141
}
4242
exprational(n) {
43-
return new Rational(
44-
Math.pow(this.numerator, n),
45-
Math.pow(this.denominator, n),
46-
);
43+
if (n >= 0) {
44+
return new Rational(
45+
Math.pow(this.numerator, n),
46+
Math.pow(this.denominator, n),
47+
);
48+
} else {
49+
return new Rational(
50+
Math.pow(this.denominator, -n),
51+
Math.pow(this.numerator, -n),
52+
);
53+
}
4754
}
4855
expreal(base) {
4956
return Math.pow(
Lines changed: 63 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,139 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[0ba4d988-044c-4ed5-9215-4d0bb8d0ae9f]
6-
description = "Add two positive rational numbers"
13+
description = "Arithmetic -> Addition -> Add two positive rational numbers"
714

815
[88ebc342-a2ac-4812-a656-7b664f718b6a]
9-
description = "Add a positive rational number and a negative rational number"
16+
description = "Arithmetic -> Addition -> Add a positive rational number and a negative rational number"
1017

1118
[92ed09c2-991e-4082-a602-13557080205c]
12-
description = "Add two negative rational numbers"
19+
description = "Arithmetic -> Addition -> Add two negative rational numbers"
1320

1421
[6e58999e-3350-45fb-a104-aac7f4a9dd11]
15-
description = "Add a rational number to its additive inverse"
22+
description = "Arithmetic -> Addition -> Add a rational number to its additive inverse"
1623

1724
[47bba350-9db1-4ab9-b412-4a7e1f72a66e]
18-
description = "Subtract two positive rational numbers"
25+
description = "Arithmetic -> Subtraction -> Subtract two positive rational numbers"
1926

2027
[93926e2a-3e82-4aee-98a7-fc33fb328e87]
21-
description = "Subtract a positive rational number and a negative rational number"
28+
description = "Arithmetic -> Subtraction -> Subtract a positive rational number and a negative rational number"
2229

2330
[a965ba45-9b26-442b-bdc7-7728e4b8d4cc]
24-
description = "Subtract two negative rational numbers"
31+
description = "Arithmetic -> Subtraction -> Subtract two negative rational numbers"
2532

2633
[0df0e003-f68e-4209-8c6e-6a4e76af5058]
27-
description = "Subtract a rational number from itself"
34+
description = "Arithmetic -> Subtraction -> Subtract a rational number from itself"
2835

2936
[34fde77a-75f4-4204-8050-8d3a937958d3]
30-
description = "Multiply two positive rational numbers"
37+
description = "Arithmetic -> Multiplication -> Multiply two positive rational numbers"
3138

3239
[6d015cf0-0ea3-41f1-93de-0b8e38e88bae]
33-
description = "Multiply a negative rational number by a positive rational number"
40+
description = "Arithmetic -> Multiplication -> Multiply a negative rational number by a positive rational number"
3441

3542
[d1bf1b55-954e-41b1-8c92-9fc6beeb76fa]
36-
description = "Multiply two negative rational numbers"
43+
description = "Arithmetic -> Multiplication -> Multiply two negative rational numbers"
3744

3845
[a9b8f529-9ec7-4c79-a517-19365d779040]
39-
description = "Multiply a rational number by its reciprocal"
46+
description = "Arithmetic -> Multiplication -> Multiply a rational number by its reciprocal"
4047

4148
[d89d6429-22fa-4368-ab04-9e01a44d3b48]
42-
description = "Multiply a rational number by 1"
49+
description = "Arithmetic -> Multiplication -> Multiply a rational number by 1"
4350

4451
[0d95c8b9-1482-4ed7-bac9-b8694fa90145]
45-
description = "Multiply a rational number by 0"
52+
description = "Arithmetic -> Multiplication -> Multiply a rational number by 0"
4653

4754
[1de088f4-64be-4e6e-93fd-5997ae7c9798]
48-
description = "Divide two positive rational numbers"
55+
description = "Arithmetic -> Division -> Divide two positive rational numbers"
4956

5057
[7d7983db-652a-4e66-981a-e921fb38d9a9]
51-
description = "Divide a positive rational number by a negative rational number"
58+
description = "Arithmetic -> Division -> Divide a positive rational number by a negative rational number"
5259

5360
[1b434d1b-5b38-4cee-aaf5-b9495c399e34]
54-
description = "Divide two negative rational numbers"
61+
description = "Arithmetic -> Division -> Divide two negative rational numbers"
5562

5663
[d81c2ebf-3612-45a6-b4e0-f0d47812bd59]
57-
description = "Divide a rational number by 1"
64+
description = "Arithmetic -> Division -> Divide a rational number by 1"
5865

5966
[5fee0d8e-5955-4324-acbe-54cdca94ddaa]
60-
description = "Absolute value of a positive rational number"
67+
description = "Absolute value -> Absolute value of a positive rational number"
6168

6269
[3cb570b6-c36a-4963-a380-c0834321bcaa]
63-
description = "Absolute value of a positive rational number with negative numerator and denominator"
70+
description = "Absolute value -> Absolute value of a positive rational number with negative numerator and denominator"
6471

6572
[6a05f9a0-1f6b-470b-8ff7-41af81773f25]
66-
description = "Absolute value of a negative rational number"
73+
description = "Absolute value -> Absolute value of a negative rational number"
6774

6875
[5d0f2336-3694-464f-8df9-f5852fda99dd]
69-
description = "Absolute value of a negative rational number with negative denominator"
76+
description = "Absolute value -> Absolute value of a negative rational number with negative denominator"
7077

7178
[f8e1ed4b-9dca-47fb-a01e-5311457b3118]
72-
description = "Absolute value of zero"
79+
description = "Absolute value -> Absolute value of zero"
80+
81+
[4a8c939f-f958-473b-9f88-6ad0f83bb4c4]
82+
description = "Absolute value -> Absolute value of a rational number is reduced to lowest terms"
7383

7484
[ea2ad2af-3dab-41e7-bb9f-bd6819668a84]
75-
description = "Raise a positive rational number to a positive integer power"
85+
description = "Exponentiation of a rational number -> Raise a positive rational number to a positive integer power"
7686

7787
[8168edd2-0af3-45b1-b03f-72c01332e10a]
78-
description = "Raise a negative rational number to a positive integer power"
88+
description = "Exponentiation of a rational number -> Raise a negative rational number to a positive integer power"
89+
90+
[c291cfae-cfd8-44f5-aa6c-b175c148a492]
91+
description = "Exponentiation of a rational number -> Raise a positive rational number to a negative integer power"
92+
93+
[45cb3288-4ae4-4465-9ae5-c129de4fac8e]
94+
description = "Exponentiation of a rational number -> Raise a negative rational number to an even negative integer power"
95+
96+
[2d47f945-ffe1-4916-a399-c2e8c27d7f72]
97+
description = "Exponentiation of a rational number -> Raise a negative rational number to an odd negative integer power"
7998

8099
[e2f25b1d-e4de-4102-abc3-c2bb7c4591e4]
81-
description = "Raise zero to an integer power"
100+
description = "Exponentiation of a rational number -> Raise zero to an integer power"
82101

83102
[431cac50-ab8b-4d58-8e73-319d5404b762]
84-
description = "Raise one to an integer power"
103+
description = "Exponentiation of a rational number -> Raise one to an integer power"
85104

86105
[7d164739-d68a-4a9c-b99f-dd77ce5d55e6]
87-
description = "Raise a positive rational number to the power of zero"
106+
description = "Exponentiation of a rational number -> Raise a positive rational number to the power of zero"
88107

89108
[eb6bd5f5-f880-4bcd-8103-e736cb6e41d1]
90-
description = "Raise a negative rational number to the power of zero"
109+
description = "Exponentiation of a rational number -> Raise a negative rational number to the power of zero"
91110

92111
[30b467dd-c158-46f5-9ffb-c106de2fd6fa]
93-
description = "Raise a real number to a positive rational number"
112+
description = "Exponentiation of a real number to a rational number -> Raise a real number to a positive rational number"
94113

95114
[6e026bcc-be40-4b7b-ae22-eeaafc5a1789]
96-
description = "Raise a real number to a negative rational number"
115+
description = "Exponentiation of a real number to a rational number -> Raise a real number to a negative rational number"
97116

98117
[9f866da7-e893-407f-8cd2-ee85d496eec5]
99-
description = "Raise a real number to a zero rational number"
118+
description = "Exponentiation of a real number to a rational number -> Raise a real number to a zero rational number"
100119

101120
[0a63fbde-b59c-4c26-8237-1e0c73354d0a]
102-
description = "Reduce a positive rational number to lowest terms"
121+
description = "Reduction to lowest terms -> Reduce a positive rational number to lowest terms"
122+
123+
[5ed6f248-ad8d-4d4e-a545-9146c6727f33]
124+
description = "Reduction to lowest terms -> Reduce places the minus sign on the numerator"
103125

104126
[f87c2a4e-d29c-496e-a193-318c503e4402]
105-
description = "Reduce a negative rational number to lowest terms"
127+
description = "Reduction to lowest terms -> Reduce a negative rational number to lowest terms"
106128

107129
[3b92ffc0-5b70-4a43-8885-8acee79cdaaf]
108-
description = "Reduce a rational number with a negative denominator to lowest terms"
130+
description = "Reduction to lowest terms -> Reduce a rational number with a negative denominator to lowest terms"
109131

110132
[c9dbd2e6-5ac0-4a41-84c1-48b645b4f663]
111-
description = "Reduce zero to lowest terms"
133+
description = "Reduction to lowest terms -> Reduce zero to lowest terms"
112134

113135
[297b45ad-2054-4874-84d4-0358dc1b8887]
114-
description = "Reduce an integer to lowest terms"
136+
description = "Reduction to lowest terms -> Reduce an integer to lowest terms"
115137

116138
[a73a17fe-fe8c-4a1c-a63b-e7579e333d9e]
117-
description = "Reduce one to lowest terms"
139+
description = "Reduction to lowest terms -> Reduce one to lowest terms"

exercises/practice/rational-numbers/rational-numbers.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,30 @@ describe('Absolute value', () => {
105105
expect(new Rational(1, 2).abs()).toEqual(expected);
106106
});
107107

108+
xtest('Absolute value of a positive rational number with negative numerator and denominator', () => {
109+
const expected = new Rational(1, 2);
110+
expect(new Rational(-1, -2).abs()).toEqual(expected);
111+
});
112+
108113
xtest('Absolute value of a negative rational number', () => {
109114
const expected = new Rational(1, 2);
110115
expect(new Rational(-1, 2).abs()).toEqual(expected);
111116
});
112117

118+
xtest('Absolute value of a negative rational number with negative denominator', () => {
119+
const expected = new Rational(1, 2);
120+
expect(new Rational(1, -2).abs()).toEqual(expected);
121+
});
122+
113123
xtest('Absolute value of zero', () => {
114124
const expected = new Rational(0, 1);
115125
expect(new Rational(0, 1).abs()).toEqual(expected);
116126
});
127+
128+
xtest('Absolute value of a rational number is reduced to lowest terms', () => {
129+
const expected = new Rational(1, 2);
130+
expect(new Rational(2, 4).abs()).toEqual(expected);
131+
});
117132
});
118133

119134
describe('Exponentiation of a rational number', () => {
@@ -127,6 +142,21 @@ describe('Exponentiation of a rational number', () => {
127142
expect(new Rational(-1, 2).exprational(3)).toEqual(expected);
128143
});
129144

145+
xtest('Raise a positive rational number to a negative integer power', () => {
146+
const expected = new Rational(25, 9);
147+
expect(new Rational(3, 5).exprational(-2)).toEqual(expected);
148+
});
149+
150+
xtest('Raise a negative rational number to an even negative integer power', () => {
151+
const expected = new Rational(25, 9);
152+
expect(new Rational(-3, 5).exprational(-2)).toEqual(expected);
153+
});
154+
155+
xtest('Raise a negative rational number to an odd negative integer power', () => {
156+
const expected = new Rational(-125, 27);
157+
expect(new Rational(-3, 5).exprational(-3)).toEqual(expected);
158+
});
159+
130160
xtest('Raise zero to an integer power', () => {
131161
const expected = new Rational(0, 1);
132162
expect(new Rational(0, 1).exprational(5)).toEqual(expected);
@@ -170,6 +200,11 @@ describe('Reduction to lowest terms', () => {
170200
expect(new Rational(2, 4).reduce()).toEqual(expected);
171201
});
172202

203+
xtest('Reduce places the minus sign on the numerator', () => {
204+
const expected = new Rational(-3, 4);
205+
expect(new Rational(3, -4).reduce()).toEqual(expected);
206+
});
207+
173208
xtest('Reduce a negative rational number to lowest terms', () => {
174209
const expected = new Rational(-2, 3);
175210
expect(new Rational(-4, 6).reduce()).toEqual(expected);

0 commit comments

Comments
 (0)