Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prime trait #563

Merged
merged 2 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ http = "0.2.6"
lazy_static = "1.4.0"
log = "0.4.14"
mime_guess = "2.0.4"
primes = "0.3.0"
rayon = "1.5.1"
redb = "0.7.0"
regex = "1.6.0"
Expand Down
4 changes: 4 additions & 0 deletions src/ordinal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ impl Ordinal {
self.into()
}

pub(crate) fn prime(self) -> bool {
primes::is_prime(self.0)
}

pub(crate) fn name(self) -> String {
let mut x = Self::SUPPLY - self.0;
let mut name = String::new();
Expand Down
28 changes: 6 additions & 22 deletions src/subcommand/server/templates/ordinal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mod tests {
<dt>period</dt><dd>0</dd>
<dt>offset</dt><dd>0</dd>
<dt>rarity</dt><dd><span class=mythic>mythic</span></dd>
<dt>prime</dt><dd>false</dd>
<dt>time</dt><dd>1970-01-01 00:00:00</dd>
<dt>percentile</dt><dd>0%</dd>
</dl>
Expand All @@ -47,32 +48,14 @@ mod tests {
}

#[test]
fn ordinal_previous() {
assert_eq!(
fn two_is_prime() {
assert_regex_match!(
OrdinalHtml {
ordinal: Ordinal::LAST,
ordinal: Ordinal(2),
blocktime: Blocktime::Confirmed(0),
}
.to_string(),
"
<h1>Ordinal 2099999997689999</h1>
<dl>
<dt>decimal</dt><dd>6929999.0</dd>
<dt>degree</dt><dd>5°209999′1007″0‴</dd>
<dt>name</dt><dd>a</dd>
<dt>block</dt><dd>6929999</dd>
<dt>cycle</dt><dd>5</dd>
<dt>epoch</dt><dd>32</dd>
<dt>period</dt><dd>3437</dd>
<dt>offset</dt><dd>0</dd>
<dt>rarity</dt><dd><span class=uncommon>uncommon</span></dd>
<dt>time</dt><dd>1970-01-01 00:00:00</dd>
<dt>percentile</dt><dd>100%</dd>
</dl>
<a href=/ordinal/2099999997689998>prev</a>
<a>next</a>
"
.unindent()
".*<dt>prime</dt><dd>true</dd>.*",
);
}

Expand All @@ -96,6 +79,7 @@ mod tests {
<dt>period</dt><dd>0</dd>
<dt>offset</dt><dd>1</dd>
<dt>rarity</dt><dd><span class=common>common</span></dd>
<dt>prime</dt><dd>false</dd>
<dt>time</dt><dd>1970-01-01 00:00:00</dd>
<dt>percentile</dt><dd>0.000000000000047619047671428595%</dd>
</dl>
Expand Down
1 change: 1 addition & 0 deletions templates/ordinal.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ <h1>Ordinal {{ self.ordinal.n() }}</h1>
<dt>period</dt><dd>{{ self.ordinal.period() }}</dd>
<dt>offset</dt><dd>{{ self.ordinal.third() }}</dd>
<dt>rarity</dt><dd><span class={{self.ordinal.rarity()}}>{{ self.ordinal.rarity() }}</span></dd>
<dt>prime</dt><dd>{{ self.ordinal.prime() }}</dd>
<dt>time</dt><dd>{{ self.blocktime }}</dd>
<dt>percentile</dt><dd>{{ self.ordinal.percentile() }}</dd>
</dl>
Expand Down