Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use serde::{Serialize, Deserialize};
- #[allow(dead_code)]
- #[derive(Serialize, Deserialize, Debug, PartialEq)]
- pub struct CreditCard {
- amount: u32,
- number: String,
- date: String,
- cvv: String,
- }
- #[allow(dead_code)]
- impl CreditCard {
- pub fn new(number: String, date: String, cvv: String) -> CreditCard {
- CreditCard {
- amount: 100_000,
- number,
- date,
- cvv,
- }
- }
- pub fn set_amount(&mut self, amount: u32) {
- self.amount = amount;
- }
- pub fn get_amount(&self) -> u32 {
- self.amount
- }
- }
- #[cfg(test)]
- mod test {
- use super::*;
- #[test]
- fn new_credit_card_test() {
- let new_cc =
- CreditCard::new("123546".to_string(), "06/09".to_string(), "669".to_string());
- assert_eq!(
- new_cc,
- CreditCard {
- amount: 100_000,
- number: "123546".to_string(),
- date: "06/09".to_string(),
- cvv: "669".to_string(),
- }
- );
- }
- #[test]
- fn set_credit_card_test() {
- let mut new_cc =
- CreditCard::new("123546".to_string(), "06/09".to_string(), "669".to_string());
- new_cc.set_amount(200_000);
- assert_eq!(new_cc.amount, 200_000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement