Skip to content

Commit 1fe58cb

Browse files
author
Charlotte Thomas
committed
Merge branch 'mistress' into github-page
2 parents a2f1273 + db59d5a commit 1fe58cb

File tree

25 files changed

+3504
-1338
lines changed

25 files changed

+3504
-1338
lines changed

.github/workflows/rust-test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: Rust
22

33
on:
44
push:
5-
branches: [ "mistress" ]
65
pull_request:
76
branches: [ "mistress" ]
87

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Version 3.0.0 : Symbolic calculation!
2+
Version 3.0.0, at last! (if you've seen the PR for it it's been sitting for more
3+
than three weeks!)
4+
5+
Symbolic computation was added you can compute expressions with symbols (such as
6+
x,y,whatever) and more !
7+
8+
# Version 2.13.2 : Bug fix
9+
Fix #43
10+
11+
# Version 2.13.1 : Bug fix
12+
Fix the issue of the function never used (moved implementation to the test
13+
module)
14+
115
# Version 2.13.0 : Update!
216
You can upgrade the calculator with `mini-calc --update`
317

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mini-calc"
3-
version = "2.13.0"
3+
version = "3.0.0"
44
license = "GPL-3.0-or-later"
55
description = "A fully-featured minimalistic configurable rust calculator"
66
homepage = "https://calc.nwa2coco.fr"

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ release:
66
cargo build --release
77
test:
88
cargo test
9+
publish:
10+
cargo publish

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ If you prefer a PDF, there is a [manual](https://calc.nwa2coco.fr/assets/manual.
5454
| [<img src="https://avatars.githubusercontent.com/u/87855546?v=4" style="border-radius: 50%;height:90pt;width:auto">](https://github.com/leana8959) |Léana 江 | Help, cleanup | [Website/Blog](https://earth2077.fr) |
5555
| [<img src="https://avatars.githubusercontent.com/u/53050011?v=4" style="border-radius:50%;height:90pt;width:auto">](https://github.com/Sigmaficient) |Sigmaficient | Nixify | [Website](https://sigmanificient.github.io/)|
5656

57-
5857
## TODO List
5958
The TODO list is completed so I collapsed it
6059
<details>

src/configuration/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn load_color(string: String) -> Color {
131131

132132
pub fn replace_variable(str: String) -> String {
133133
str.replace("%author%", "Charlotte Thomas")
134-
.replace("%version%", "v2.13.0")
134+
.replace("%version%", "v3.0.0")
135135
.to_string()
136136
}
137137

src/exact_math/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub mod rationals;
2+
pub mod symbolic;

src/exact_math/rationals.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{fmt::Display, ops};
22

33
use crate::utils::integer_utils::gcd;
44

5-
#[derive(Debug, Clone)]
5+
#[derive(Debug, Clone, Copy)]
66
pub struct Rationals {
77
pub under: i64,
88
pub over: i64,
@@ -32,6 +32,17 @@ impl Rationals {
3232
return self.over == 0;
3333
}
3434

35+
pub fn opposite(self) -> Self {
36+
Rationals::new(self.under, -1 * self.over)
37+
}
38+
39+
pub fn invert(self) -> Result<Rationals, Rationals> {
40+
match self.over {
41+
0 => Err(Rationals::new(0, 1)),
42+
_ => Ok(Rationals::new(self.over, self.under).reduce()),
43+
}
44+
}
45+
3546
pub fn reduce(self) -> Self {
3647
let minus;
3748
let i1;
@@ -84,7 +95,7 @@ impl Rationals {
8495

8596
impl Display for Rationals {
8697
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
87-
let fs = self.clone().reduce();
98+
let fs = self.reduce();
8899
if fs.under == 1 {
89100
write!(f, "{}", fs.over)
90101
} else {

src/exact_math/symbolic.rs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
use crate::parsing::ast::Parameters;
2+
use crate::parsing::ast::Parameters::*;
3+
4+
pub fn size(p: &Parameters) -> i32 {
5+
match p {
6+
Null
7+
| Int(_)
8+
| Str(_)
9+
| Float(_)
10+
| Identifier(_)
11+
| PlusOperation
12+
| MinusOperation
13+
| MultiplicationOperation
14+
| DivideOperation
15+
| Assign
16+
| ExpoOperation
17+
| GreaterOperation
18+
| GreaterOrEqualOperation
19+
| LesserOperation
20+
| LesserOrEqualOperation
21+
| Equal
22+
| Bool(_)
23+
| Rational(_)
24+
| OrOperation
25+
| AndOperation
26+
| Not
27+
| Vector(_)
28+
| InterpreterVector(_) => 0,
29+
Plus(x, y) => 1 + size(x) + size(y),
30+
Var(x, _, _) => 1 + size(x),
31+
Mul(x, y) => 1 + size(x) + size(y),
32+
Div(x, y) => 1 + size(x) + size(y),
33+
}
34+
}
35+
36+
#[cfg(test)]
37+
mod test {
38+
39+
use crate::{
40+
exact_math::rationals::Rationals,
41+
parsing::ast::{
42+
Ast,
43+
Parameters::{self, *},
44+
},
45+
};
46+
47+
use super::size;
48+
#[test]
49+
fn test_leaf() {
50+
let v = vec![
51+
Null,
52+
Int(1),
53+
Str("".to_string()),
54+
Float(1.0),
55+
Identifier("".to_string()),
56+
PlusOperation,
57+
MinusOperation,
58+
MultiplicationOperation,
59+
DivideOperation,
60+
Assign,
61+
ExpoOperation,
62+
GreaterOperation,
63+
GreaterOrEqualOperation,
64+
LesserOperation,
65+
LesserOrEqualOperation,
66+
Equal,
67+
Bool(false),
68+
Rational(Rationals::new(10, 10)),
69+
OrOperation,
70+
AndOperation,
71+
Not,
72+
Vector(Box::from(vec![Ast::Nil])),
73+
InterpreterVector(Box::from(vec![Null])),
74+
];
75+
76+
let should = vec![
77+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
78+
0, 0, 0, 0, 0,
79+
];
80+
81+
let _ = v
82+
.into_iter()
83+
.map(|f| size(&f))
84+
.zip(should)
85+
.for_each(|(x, y)| assert_eq!(x, y));
86+
}
87+
88+
#[test]
89+
fn test_size() {
90+
let should = 2;
91+
let tree = Plus(
92+
Box::from(Plus(
93+
Box::from(Parameters::Int(1)),
94+
Box::from(Parameters::Int(2)),
95+
)),
96+
Box::from(Parameters::Int(3)),
97+
);
98+
let result = size(&tree);
99+
assert_eq!(result, should);
100+
}
101+
#[test]
102+
fn test_size_mul() {
103+
let should = 2;
104+
let tree = Mul(
105+
Box::from(Plus(
106+
Box::from(Parameters::Int(1)),
107+
Box::from(Parameters::Int(2)),
108+
)),
109+
Box::from(Parameters::Int(3)),
110+
);
111+
let result = size(&tree);
112+
assert_eq!(result, should);
113+
}
114+
#[test]
115+
fn test_size_var() {
116+
let should = 1;
117+
let tree = Var(Box::from(Parameters::Int(1)), 1, "s".to_string());
118+
let result = size(&tree);
119+
assert_eq!(result, should);
120+
}
121+
}

0 commit comments

Comments
 (0)