@@ -51,7 +51,7 @@ impl Ord for DevilFruit {
5151
5252impl PartialOrd for DevilFruit {
5353 fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
54- self . df_url . partial_cmp ( & other. df_url )
54+ Some ( self . cmp ( other) )
5555 }
5656}
5757
@@ -86,3 +86,75 @@ impl UrlTyped for Character {
8686 format ! ( "/wiki/Character:{}" , self . id)
8787 }
8888}
89+
90+ #[ cfg( test) ]
91+ mod tests {
92+ use crate :: {
93+ df:: {
94+ models:: DfTypeInfo ,
95+ types:: { DfSubType , DfType } ,
96+ } ,
97+ types:: UrlTyped ,
98+ } ;
99+
100+ use super :: { Character , DevilFruit } ;
101+
102+ #[ test]
103+ fn df_has_valid_traits ( ) {
104+ let dftype = DfTypeInfo {
105+ df_type : DfType :: Logia ,
106+ cannon_count : 10 ,
107+ non_cannon_count : 1 ,
108+ description : "logia" . to_string ( ) ,
109+ } ;
110+ assert_eq ! (
111+ format!( "{}" , dftype) ,
112+ "(df_type: Logia, cannon: 10, non-cannon: 1, description: logia)"
113+ ) ;
114+ let df1 = DevilFruit {
115+ df_type : DfType :: Zoan ,
116+ df_sub_type : Some ( DfSubType :: MythicalZoan ) ,
117+ name : "Nika" . to_string ( ) ,
118+ en_name : "Nika" . to_string ( ) ,
119+ description : "Used to Gomu" . to_string ( ) ,
120+ pic_url : "pic" . to_string ( ) ,
121+ df_url : "nika" . to_string ( ) ,
122+ } ;
123+ let df2 = DevilFruit {
124+ df_type : DfType :: Zoan ,
125+ df_sub_type : Some ( DfSubType :: MythicalZoan ) ,
126+ name : "Zeus" . to_string ( ) ,
127+ en_name : "Zeus" . to_string ( ) ,
128+ description : "Greek" . to_string ( ) ,
129+ pic_url : "pic" . to_string ( ) ,
130+ df_url : "zeus" . to_string ( ) ,
131+ } ;
132+ let df3 = DevilFruit {
133+ df_type : DfType :: Zoan ,
134+ df_sub_type : Some ( DfSubType :: MythicalZoan ) ,
135+ name : "Nika" . to_string ( ) ,
136+ en_name : "Nika" . to_string ( ) ,
137+ description : "Used to Gomu" . to_string ( ) ,
138+ pic_url : "pic" . to_string ( ) ,
139+ df_url : "nika" . to_string ( ) ,
140+ } ;
141+ assert_ne ! ( df1, df2) ;
142+ assert_eq ! ( df1, df3) ;
143+ assert ! ( df1 < df2) ;
144+ assert_eq ! (
145+ format!( "{}" , df1) ,
146+ format!( "(df_type: {}, df_sub_type: {:?}, name: {}, english name: {}, pic: {}, url: {}, description: {})" ,
147+ df1. df_type, df1. df_sub_type, df1. name, df1. en_name, df1. pic_url, df1. df_url, df1. description
148+ ) ) ;
149+ }
150+
151+ #[ test]
152+ fn char_has_valid_traits ( ) {
153+ let character = Character {
154+ id : "1234" . to_string ( ) ,
155+ name : "Foo" . to_string ( ) ,
156+ pic_url : "pic" . to_string ( ) ,
157+ } ;
158+ assert_eq ! ( character. get_path( ) , "/wiki/Character:1234" ) ;
159+ }
160+ }
0 commit comments