[types] Passing integer tests and build fixes
This commit is contained in:
		
							parent
							
								
									3bdf14720c
								
							
						
					
					
						commit
						68eec8578c
					
				
					 2 changed files with 17 additions and 19 deletions
				
			
		| 
						 | 
					@ -3,13 +3,22 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use std::any::Any;
 | 
					use std::any::Any;
 | 
				
			||||||
 | 
					use std::fmt;
 | 
				
			||||||
use number::Number;
 | 
					use number::Number;
 | 
				
			||||||
use object::{Obj, Object};
 | 
					use object::{Obj, Object};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub type Int = i64;
 | 
					#[derive(Debug, Eq, PartialEq)]
 | 
				
			||||||
 | 
					pub struct Int(i64);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl fmt::Display for Int {
 | 
				
			||||||
 | 
					    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 | 
				
			||||||
 | 
					        write!(f, "{}", self.0)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Object for Int {
 | 
					impl Object for Int {
 | 
				
			||||||
    fn as_any(&self) -> &Any { self }
 | 
					    fn as_any(&self) -> &Any { self }
 | 
				
			||||||
 | 
					    fn as_num(&self) -> Option<&Number> { Some(self) }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Number for Int {
 | 
					impl Number for Int {
 | 
				
			||||||
| 
						 | 
					@ -36,32 +45,23 @@ impl<'a> PartialEq<Number + 'a> for Int {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(test)]
 | 
					#[cfg(test)]
 | 
				
			||||||
mod tests {
 | 
					mod tests {
 | 
				
			||||||
    use super::Int;
 | 
					    use super::*;
 | 
				
			||||||
    use number::*;
 | 
					 | 
				
			||||||
    use value::*;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[test]
 | 
					    #[test]
 | 
				
			||||||
    fn equal_integers_are_equal() {
 | 
					    fn equal_integers_are_equal() {
 | 
				
			||||||
        assert_eq!(Integer(3), Integer(3));
 | 
					        assert_eq!(Int(3), Int(3));
 | 
				
			||||||
        assert_ne!(Integer(12), Integer(9));
 | 
					        assert_ne!(Int(12), Int(9));
 | 
				
			||||||
        assert_eq!(Integer(4).as_value(), Integer(4).as_value());
 | 
					        assert_eq!(Obj::new(Int(3)), Obj::new(Int(3)));
 | 
				
			||||||
        assert_ne!(Integer(5).as_value(), Integer(7).as_value());
 | 
					        assert_ne!(Obj::new(Int(3)), Obj::new(Int(4)));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[test]
 | 
					    #[test]
 | 
				
			||||||
    fn integers_are_integers() {
 | 
					    fn integers_are_integers() {
 | 
				
			||||||
        assert!(Integer(4).is_complex());
 | 
					        assert_eq!(Int(4).as_bool(), None);
 | 
				
			||||||
        assert!(Integer(4).is_real());
 | 
					 | 
				
			||||||
        assert!(Integer(4).is_rational());
 | 
					 | 
				
			||||||
        assert!(Integer(4).is_integer());
 | 
					 | 
				
			||||||
        assert!(Integer(4).is_number());
 | 
					 | 
				
			||||||
        assert!(!Integer(6).is_char());
 | 
					 | 
				
			||||||
        assert!(!Integer(6).is_bool());
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[test]
 | 
					    #[test]
 | 
				
			||||||
    fn integers_are_exact() {
 | 
					    fn integers_are_exact() {
 | 
				
			||||||
        assert!(Integer(4).is_exact());
 | 
					        assert!(Int(4).is_exact());
 | 
				
			||||||
        assert!(!Integer(4).is_inexact());
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -188,8 +188,6 @@ impl PartialEq for Obj {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(test)]
 | 
					#[cfg(test)]
 | 
				
			||||||
mod tests {
 | 
					mod tests {
 | 
				
			||||||
    use super::Obj;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//    #[test]
 | 
					//    #[test]
 | 
				
			||||||
//    fn display_bools() {
 | 
					//    fn display_bools() {
 | 
				
			||||||
//        assert_eq!(format!("{}", Object::Bool(true)), "#t");
 | 
					//        assert_eq!(format!("{}", Object::Bool(true)), "#t");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue