Академический Документы
Профессиональный Документы
Культура Документы
Select: (p) postpone, (df) show diff, (e) edit file, (m) merge,
(mc) my side of conflict, (tc) their side of conflict,
(s) show all options: df
--- lab3/lab3.rkt.r7 - THEIRS
+++ lab3/lab3.rkt - MERGED
@@ -1,3 +1,4 @@
+<<<<<<< .mine
#lang typed/racket
(require typed/test-engine/racket-tests)
@@ -26,6 +27,147 @@
(check-expect (leap? 800) #t )
(: days-in-month (Integer Integer -> Integer))
+;;gives the days in a month: smart-construct-date-helper
+(define (days-in-month m y)
+ (cond
+ [(or (= m 1)(= m 3)(= m 5)(= m 7)(= m 8)(= m 10) (= m 12)) 31]
+ [(or (= m 4)(= m 6)(= m 9)(= m 11)) 30]
+ [(and (= m 2) (leap? y)) 29]
+ [(and (= m 2) (not(leap? y)) 28)]
+ [else (error "not a month")]))
+(check-expect (days-in-month 2 2016) 29)
+(check-expect (days-in-month 2 4000) 29)
+(check-expect (days-in-month 2 2017) 28)
+(check-expect (days-in-month 1 2016) 31)
+(check-expect (days-in-month 4 2016) 30)
+
+(: reasonable-day (Integer Integer Integer -> Boolean))
+;;checks if day is reasaonble for the month and year: smart-construct-date helper
+(define (reasonable-day m d y)
+ (cond
+ [(<= 1 d (days-in-month m y)) #t]
+ [else #f]))
+(check-expect (reasonable-day 2 29 2016) #t)
+(check-expect (reasonable-day 2 29 4000) #t)
+(check-expect (reasonable-day 2 29 2017) #f)
+(check-expect (reasonable-day 1 31 2016) #t)
+(check-expect (reasonable-day 4 10 1998) #t)
+
+(: smart-construct-date (Integer Integer Integer -> Date))
+;;gives a date if month, day, and year given are reasonable
+(define (smart-construct-date m d y)
+ (cond
+ [(and (<= 1 m 12)
+ (<= 1900 y 2099)
+ (reasonable-day m d y))
+ (Date m d y)]
+ [else (error "dates not reasonable or not in 20th/21st century")]))
+(check-expect (smart-construct-date 2 29 2016) (Date 2 29 2016))
+(check-expect (smart-construct-date 8 26 1999) (Date 8 26 1999))
+(check-expect (smart-construct-date 7 13 1997) (Date 7 13 1997))
+(check-error (smart-construct-date 2 29 2017)
+ "dates not reasonable or not in 20th/21st century")
+(check-error (smart-construct-date 4 31 2017)
+ "dates not reasonable or not in 20th/21st century")
+(check-error (smart-construct-date 1 31 1776)
+ "dates not reasonable or not in 20th/21st century")
+
+(: date=? (Date Date -> Boolean))
+;;check if two dates are exactly the same
+(define (date=? d1 d2)
+ (cond
+ [(and (= (Date-d d1) (Date-d d2))
+ (= (Date-m d2) (Date-m d2))
+ (= (Date-y d1) (Date-y d2))) #t]
+ [else #f]))
+(check-expect (date=? (Date 1 2 1999) (Date 1 2 1999)) #t)
+(check-expect (date=? (Date 1 2 1999) (Date 1 10 1999)) #f)
+(check-expect (date=? (Date 2 28 1999) (Date 2 1 1999)) #f)
+
+(: date<? (Date Date -> Boolean))
+;;check if first date occurs before the second
+(define (date<? d1 d2)
+ (cond
+ [(and (< (Date-d d1) (Date-d d2))
+ (<= (Date-m d2) (Date-m d2))
+ (<= (Date-y d1) (Date-y d2))) #t]
+ [else #f]))
+(check-expect (date<? (Date 1 2 1999) (Date 1 10 1999)) #t)
+(check-expect (date<? (Date 1 2 1999) (Date 1 2 1999)) #f)
+(check-expect (date<? (Date 3 28 1999) (Date 3 20 1999)) #f)
+
+(: month-adj (Integer Integer -> Integer))
+;;return j, the month adjustment
+(define (month-adj m y)
+(cond
+ [(or(= m 3)(= m 11)) 4 ]
+ [(or(= m 4)(= m 7)) 0 ]
+ [(= m 8) 3 ]
+ [(or(= m 9)(= m 12)) 6]
+ [(= m 6) 5]
+ [(= m 5) 2]
+ [(= m 10) 1]
+ [(and (leap? y)(= m 1)) 0]
+ [(and (leap? y)(= m 2)) 3]
+ [(and (not(leap? y))(= m 1)) 1]
+ [(and (not(leap? y))(= m 2)) 4]
+ [else (error "need reasonable months and dates")]
+ ))
+(check-expect (month-adj 6 2016) 5)
+(check-expect (month-adj 2 2016) 3)
+(check-expect (month-adj 2 2017) 4)
+(check-expect (month-adj 12 2017) 6)
+
+(: day-of-week (Date -> Day))
+;;determines the the day of the week given a date
+(define (day-of-week date)
+(match (remainder (+ (- (Date-y date) 1900)
+ (month-adj (Date-m date) (Date-y date))
+ (Date-d date)
+ (exact-floor(/ (Date-y date) 4)))
+ 7)
+ [0 'Sun]
+ [1 'Mon]
+ [2 'Tue]
+ [3 'Wed]
+ [4 'Thu]
+ [5 'Fri]
+ [6 'Sat]
+
+ ))
+(check-expect (day-of-week (Date 10 12 2017)) 'Thu )
+
+
+(test)||||||| .r0
+=======
+#lang typed/racket
+
+(require typed/test-engine/racket-tests)
+(require "../include/cs151-core.rkt")
+
+(define-struct Date
+ ([m : Integer] ;; 1 for Jan, 2 for Feb, ..., 12 for Dec
+ [d : Integer]
+ [y : Integer]))
+
+(define-type Day
+ (U 'Sun 'Mon 'Tue 'Wed 'Thu 'Fri 'Sat))
+
+(: leap? (Integer -> Boolean))
+;; compute whether or not a year is a leap year
+(define (leap? year)
+ (cond
+ [(or (and (=(remainder year 4) 0) (>(remainder year 100) 0))
+ (=(remainder year 400) 0)) #t]
+ [(< year 0) (error "expected positive year")]
+ [else #f]))
+(check-expect (leap? 2016) #t )
+(check-expect (leap? 2012) #t )
+(check-expect (leap? 2017) #f )
+(check-expect (leap? 400) #t )
+(check-expect (leap? 800) #t )
+
+(: days-in-month (Integer Integer -> Integer))
;;gives the days in a month
(define (days-in-month m year)
(cond
@@ -63,4 +205,4 @@
;; [else (error "dates not reasonable or not in 20th/21st century")]))
;
-(test)
\ No newline at end of file
+(test)>>>>>>> .r7
Select: (p) postpone, (df) show diff, (e) edit file, (m) merge,
(r) mark resolved, (mc) my side of conflict,
(tc) their side of conflict, (s) show all options: s
Select: (p) postpone, (df) show diff, (e) edit file, (m) merge,
(r) mark resolved, (mc) my side of conflict,
(tc) their side of conflict, (s) show all options: mc
Resolved conflicted state of 'lab3/lab3.rkt'
Summary of conflicts:
Text conflicts: 0 remaining (and 1 already resolved)
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$ svn status
A hw1.rkt
? include/compiled
M lab3/lab3.rkt
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$ cd ..
Guans-MacBook-Pro:~ guanwu$ svn add wuhua-cs151-aut-17/
svn: warning: W150002: '/Users/guanwu/wuhua-cs151-aut-17' is already under version control
svn: E200009: Could not add all targets because some targets are already versioned
svn: E200009: Illegal target for the requested operation
Guans-MacBook-Pro:~ guanwu$ cd wuhua-cs151-aut-17/
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$ ls
hw1 hw1.rkt hw1.rkt~ include lab1 lab3
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$ cd ..
Guans-MacBook-Pro:~ guanwu$ svn commit wuhua-cs151-aut-17/ -m "recommitting repo
folder"
Adding wuhua-cs151-aut-17/hw1.rkt
Sending wuhua-cs151-aut-17/lab3/lab3.rkt
Transmitting file data ..done
Committing transaction...
Committed revision 8.
Guans-MacBook-Pro:~ guanwu$ ls
Applications Downloads Pictures wuhua-cs151-aut-17
CS Library Public
Desktop Movies sshkey
Documents Music sshkey.pub
Guans-MacBook-Pro:~ guanwu$ cd wuhua-cs151-aut-17/
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$ svn add
svn: E205001: Try 'svn help add' for more information
svn: E205001: Not enough arguments provided
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$ svn add lab3
svn: warning: W150002: '/Users/guanwu/wuhua-cs151-aut-17/lab3' is already under version
control
svn: E200009: Could not add all targets because some targets are already versioned
svn: E200009: Illegal target for the requested operation
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$ svn commit lab3 -m "commit lab3"
Sending lab3/lab3.rkt
Transmitting file data .done
Committing transaction...
Committed revision 9.
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$ cal 8 26 199
usage: cal [-jy] [[month] year]
cal [-j] [-m month] [year]
ncal [-Jjpwy] [-s country_code] [[month] year]
ncal [-Jeo] [year]
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$ man cal
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$ svn commit lab3 -m "commit lab3"
Sending lab3/lab3.rkt
Transmitting file data .done
Committing transaction...
Committed revision 10.
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$ svn commit lab3 -m "commit lab3"
Sending lab3/lab3.rkt
Transmitting file data .done
Committing transaction...
Committed revision 11.
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$ svn commit lab3 -m "commit lab3"
Guans-MacBook-Pro:wuhua-cs151-aut-17 guanwu$