Browse code

modify tests to use the new calling convention for onsite functions

Joseph Weston authored on 09/09/2019 13:30:14
Showing 1 changed files
... ...
@@ -120,12 +120,24 @@ def test_operator_construction():
120 120
     # test construction with dict `onsite`
121 121
     for A in opservables:
122 122
         B = A(fsyst, {lat: 1})
123
-        assert all(B.onsite(i) == 1 for i in range(N))
123
+        start_sites = [r[0] for r in fsyst.site_ranges]
124
+        for site_range, (start, stop) in enumerate(zip(start_sites, start_sites[1:])):
125
+            site_offsets = np.arange(stop - start)
126
+            should_be = np.ones(len(site_offsets), complex).reshape(-1, 1, 1)
127
+            vals = B.onsite(site_range, site_offsets)
128
+            assert np.all(vals == should_be)
124 129
 
125 130
     # test construction with a functional onsite
126 131
     for A in opservables:
127 132
         B = A(fsyst, lambda site: site.pos[0])  # x-position operator
128
-        assert all(B.onsite(i) == fsyst.sites[i].pos[0] for i in range(N))
133
+        start_sites = [r[0] for r in fsyst.site_ranges]
134
+        for site_range, (start, stop) in enumerate(zip(start_sites, start_sites[1:])):
135
+            site_offsets = np.arange(stop - start)
136
+            should_be = np.array([
137
+                fsyst.sites[i].pos[0] for i in range(start, stop)
138
+            ], complex).reshape(-1, 1, 1)
139
+            vals = B.onsite(site_range, site_offsets)
140
+            assert np.all(vals == should_be)
129 141
 
130 142
     # test construction with `where` given by a sequence
131 143
     where = [lat(2, 2), lat(1, 1)]